Thursday, November 27, 2008

Set up virtual host on MAMP

1. Open your httpd.conf
This file will reside in /Applications/MAMP/conf/apache/httpd.conf .

2. Go to the bottom of httpd.conf find the vhost section, usually locates at the bottom of the file,
add virtual host like this:
<====IF PORT SET TO 8080 ==>
NameVirtualHost *:8080


ServerName dev.domain.net
DocumentRoot /Applications/MAMP/htdocs/dev_domain



ServerName test.domain.net
DocumentRoot /Applications/MAMP/htdocs/test_domain


<====IF PORT SET TO 80 ==>
NameVirtualHost *:80


ServerName dev.domain.net
DocumentRoot /Applications/MAMP/htdocs/dev_domain



ServerName test.domain.net
DocumentRoot /Applications/MAMP/htdocs/test_domain



3. Modify host file, the host file is located at:
/etc/hosts

Open the file, then add entry:
127.0.0.1 dev.domanin.net
127.0.0.1 test.domain.net

4. Restart Apache server.

NOTE:
IF YOU ARE USING PORT 8080 FOR MAMP, YOU CAN ACCESS THE SITE LIKE: http:test.domain.com:8080
IF YOU ARE USING PORT 80 FOR MAMP, YOU CAN ACCESS THE SITE LIKE: http:test.domain.com (If you cannt restar apache from MAMP after set the port 80, make sure no other apache server is using the port already)