How to set up virtual hosts on MAMP

Posted on May 26, 2014 in Web Dev

This is something I found myself Googling every time I needed it. That was until I actually just sat down and  thought about what it was I was doing when I needed to set up a new local virtual host. This really isn’t difficult at all, but there are some file paths that need remembering. These are:

  • Hosts – /private/etc/hosts
  • Httpd.conf – /Applications/MAMP/conf/apache/httpd.conf

Step 1

Add your chosen domain to your hosts file. Open up Terminal and then type:

sudo nano -w /private/etc/hosts

Then add in the following to the bottom of this file (it doesn’t really matter if it’s at the bottom or not, but I generally add new ones to the bottom):

I like to use the “.dev” extension for any ‘local’ domains I set up.

Step 2

Navigate over to the following location in Finder:


Now open up Httpd.conf in a text editor. You can do this in nano or vi, but I prefer to just use my favourite text editor (Sublime text!).

This is where tutorials on this can vary. You can either include a separate dedicated vhosts conf file into the main httpd.conf, OR you can just add your vhosts to the bottom of the httpd.conf file. It really doesn’t matter. From an organisational point of view then it’s probably better to have a separate of concerns and go with the vhosts.conf file (/extra/vhosts.conf). If you go this route then make sure you uncomment the vhosts line in your httpd.conf file.

Anyway, here’s what you need to do. Copy a paste this into the bottom of your httpd.conf file (or vhosts.conf file if that’s what you’d like to use):

<VirtualHost *:8888>
DocumentRoot /sites/mydomain/public_html/

Directory /sites/mydomain/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Make sure your location is correct. I personally have a folder outside of htdocs, whereas many people keep their sites within htdocs. All of my sites can be found at /sites/, whereas yours may be at /Applications/MAMP/htdocs/.

Step 3

Save everything and restart MAMP.

Step 4

Enjoy your local domain 🙂
Let me know if you have any questions – I’m happy to help!

Leave a comment

Was this helpful? Did I miss something? Do you have a question? Get in touch, or tell me below.