Setting up virtual hosting with MAMP

My apologies for not posting anything lately but I’ve been really busy developing several Magento shops. Normally I have the luxury to start development early on a test domain but for a more recent assignment this wasn’t the case. When I decided to start working on this webshop locally I encountered big problems with Magento running in a vanilla MAMP setup so I decided to share with you how you can easily turn MAMP into a more solid testing environment.

First of all get the latest version of MAMP. After installing this just follow the steps below.

Step 1: Configuring Apache

Since the default MAMP installation doesn’t offer pre-configured virtual hosting you have to add it yourself. Of course we always start by backing up our current configuration files. This can be easily done by opening Terminal and running the following commands.

cd /Applications/MAMP/conf/apache/
cp httpd.conf httpd.conf.bak

Now open httpd.conf in your favorite text-editor ( I suggest vi ) and add the following line at the end of the file.

Include /Applications/MAMP/conf/apache/sites

This extra line points Apache to the configuration files sites which we are about to create. You can also add the configuration to httpd.conf itself but that would result in a big and messy file if you decided to add more domain configurations. So for the sake of keeping things readable and maintainable we create a new file. Just run the following line in Terminal.

vi /Applications/MAMP/conf/apache/sites

And enter the following configuration into the file.

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /Users/yourusername/Documents/websites/

So in your Documents folder in OS X you can now create a folder called websites and in that folder you create a folder called This folder will function as the document root for your new locally hosted website.

Step 2: Tweaking your hosts file

I won’t dive into the functions of the hosts file itself because there already is a very clear explanation on it on Wikipedia. Just open up your hosts file in Terminal with the following line. You might be asked for your admin password for this.

sudo vi /etc/hosts

Then look for the line for then edit it to look like this.       localhost

You can always add more domains to it like this.       localhost

Save and quit your hosts file and run the following command in Terminal to flush your DNS cache.

dscacheutil -flushcache

And that’s that! You can now open up your browser and go to to start the development of your local website.

Side note

You’ve noticed that I decided to use the domain and this is because of when you use the actual domain name of the production version of the website you won’t be able to ‘reach’ it. Also be sure to clean up the test domains once in a while because you’re going to mix up the test version and the production version of your websites at least once.

One Reply to “Setting up virtual hosting with MAMP”

Comments are closed.