Create Multiple Localhosts April 2nd, 2015

Change Default Listening Port

Go to MAMP > Preferences > Ports and set Apache Port to be 80.

Set up Localhosts in Hosts File

Edit your hosts file so that you have some domains that will resolve to your local web server…

sudo pico /etc/hosts

Add the domains you want to resolve to your localhost…

127.0.0.1 local.example.com
127.0.0.1 my-github-repo

Add Virtual Hosts to your Apache Config

Open up /Applications/MAMP/conf/apache/httpd.conf in a text editor, scroll down, and add the following lines to the file…

NameVirtualHost *

<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>

<VirtualHost *>
DocumentRoot "/Users/YOURNAME/sites/example-a"
ServerName local.example.com
</VirtualHost>

<VirtualHost *>
DocumentRoot "/Users/YOURNAME/Downloads/my-github-repo"
ServerName my-github-repo
</VirtualHost>

Restart Apache

Stop Servers and then Start Servers on MAMP. Now you can visit the URL’s you configured like http://local.example.com/ and http://my-github-repo/

Resources