Để tạo virtual hosts trên MAMP các bạn làm theo các bước sau :
1, Cho phép sử dụng máy chủ ảo – Allow virtual hosts
Đầu tiên các bạn tìm đến Applications > MAMP > conf > apache > httpd.conf
Tìm kiếm dòng:
1 2 |
# Virtual hosts #Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf |
Tại dòng include loại bỏ comment đi như sau và thực hiện lưu lại:
1 2 |
# Virtual hosts Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf |
2, Cho phép ghi đè SymLink – Allow SymLink Override
Tìm dòng này trong file /Applications/MAMP/conf/apache/httpd.conf.
1 2 3 4 |
<Directory /> Options Indexes FollowSymLinks AllowOverride None </Directory> |
Thay thế bằng dòng sau và thực hiện lưu lại:
1 2 3 4 |
<Directory /> Options Indexes FollowSymLinks AllowOverride All </Directory> |
3, Thêm đường dẫn máy chủ ảo – Add the virtual host path
Tìm và mở file Applications > MAMP > conf > apache > extra > httpd-vhosts.conf
Thêm máy chủ ảo , đường dẫn như đoạn code ví dụ sau:
1 2 3 4 |
<VirtualHost *:80> ServerName example.local DocumentRoot "/path/to/directory" </VirtualHost> |
4, Cho phép máy tính của bạn nhận diện tên miền cục bộ – Allow your computer to recognize your local domain
Mở terminal của bạn lên và gõ :
1 |
sudo pico /etc/hosts |
Thêm tên miền cục bộ và thực hiện lưu lại :
1 |
127.0.0.1 example.local |
5, Thực hiện restart server – Restart your server.
Sau khi restart server xong, các bạn có thể truy cập vào url example.local từ trình duyệt của bạn.
Neartech xin trân trọng cảm ơn bạn đã quan tâm bài viết này! Nếu bạn gặp khó khăn gì hãy để lại comment ở bên dưới, nếu có thể mình sẽ giúp đỡ bạn!