Local Domains in MAMP (Virtual Hosts)

These intructions are for the free version of MAMP for getting the virtual hosts functionality seen in MAMP Pro. I also have these instructions in a video.

(This has been tested in version 2 and 3 of MAMP)

Set MAMP’s ports

Open up MAMP, click on preferences, then go to the ports tab. Click “Set to defualt Apache and MySQL ports”. Click okay and shutdown MAMP.

Set the domain in the hosts

Open up a terminal and navigate to your root user directory. Then do these commands (you may have to use sudo):

$ cd /etc/
$ nano hosts

Look for the line that says: localhost

Add a space and then the name you would like to use. I’ll use test.dev: localhost test.dev

Now save the document.

Allow Virtual Hosts in MAMP

Virtual hosts are turned off by default. To turn this feature on open /Applications/MAMP/conf/apach2/httpd.conf and search for the following lines (usually at the bottom of the file):

# Virtual hosts
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Now simply uncomment the line so it looks like:

# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Set the domain in the MAMP config

Unlike the MAMP Pro, the free version of MAMP does not have a gui for adding and removing custom domains (virtual hosts). There is an easy workaround though.

Navigate to /Applications/MAMP/conf/apache/extra/ in the finder. Then open up the document named httpd-vhosts.conf.

At the bottom of the document add this code for your custom doamin. Again, in this example I’m using the domain test.dev and a directory named test.dev in my sites directory:

<VirtualHost *:80>
ServerName test.dev
ServerAlias www.test.dev
DocumentRoot /Users/noah/Sites/test.dev/
<Directory /Users/noah/Sites/test.dev/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

Get MAMP and Chrome Running

Now you can open MAMP and start up its servers.

Quit and reopen Chrome if it wasn’t already off during this process and go to http://test.dev in this case.

You now have a local domain set up for developing purposes!