So you’ve installed MAMP and its been working fine for your one site you’ve been developing locally. However like most developers you are probably now working on several projects at a time or perhaps you are using a framework that does not like the “localhost” url.
For the issue of multiple websites, there are a couple of solutions. MAMP makes it pretty easy to switch your document root folder in their settings. Another option is to support the MAMP team and go pro.
However if you are a do-it-yourself-er. Here is how to set up virtual hosts with MAMP
First edit your hosts file to create your custom local domain. I use the vim editor but you can use your favorite. You will need root access to edit your hosts file.
sudo vim /etc/hosts
Once you access you hosts file, add the following line to tell it to redirect your custom url to you MAMP server.
The next step is to create the folder where you want your web content to reside. The default is the MAMP htdocs folder, but i like to create my sites under a Sites folder in my home directory for example:
Ok now we need to edit the apache config file and tell it to to enable virtual hosts. Open the following file “Applications/MAMP/conf/apache/httpd.conf” and un-comment or add the following line.
Save and close.
Now lets tell apache about our site content folder. Edit the file “/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf” adding the following minimal tag block.
<VirtualHost *:80> DocumentRoot /Users/darren/Sites/test ServerName test.local </VirtualHost>
Save and close.
Thats all there is to it. Simply restart apache with MAMP and point your browser to test.local.