Using virtual hosts with MAMP free

mamp vs mamp pro virtualhosts localhost

MAMP PRO supports the easy setup of custom domains like awesomeproject.local for developing your web projects. Since I like to stick to learning technologies I found a way to enable the same behaviour in the free version of MAMP.

Basically you need to edit three files to use the virtual hosts with the free version of MAMP, to be able to use domains like: project_name.test in your address bar and without MAMP PRO.

First, enable loading the vhosts config file placed in /Applications/MAMP/conf/apache/extra/.

 Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 

to the file /Applications/MAMP/conf/apache/httpd.conf

Now you’re ready to edit the httpd-vhosts.conf file and add the hosts for the projects you want to work on.


 <VirtualHost *:80>
DocumentRoot "/Users/username/public_html/project_name.devl/"
ServerName project_name.devl

However, you should remember to put the following at the bottom of the file, so you still can access all your projects by simply going to http://localhost/

 <VirtualHost *:80>
DocumentRoot "/Users/username/public_html/"
ServerName localhost

This line needs to be at the bottom of your file at all times, even when you add more virtual hosts to this config.

Lastly, make sure you have administrator priviledges to edit the hosts file located in /etc/hosts and add: project_name.devl 

or if you want to use IPv6

 ::1 project_name.devl 

For completeness sake I have to say, that usually developers use suffixes like .local, .loc or .dev for accessing projects locally, so that’s all up to your imagination what you write after the dot. Just make sure to make it the same in every file for this custom, but local top level domain. I’ve just chosen .devl because it’s up for interpretation if it’s for devil or developer 😉 and with programming, often the devil is in the detail.

Use case

Through a comment I’m thankful for, I realised that I should probably supply a use case for this.

For example when you define the RewriteBase in your .htaccess file, this technique can become very handy, since you don’t have to keep one version of it for your remote host and one locally, but can in both cases use something like this:

 RewriteEngine On RewriteBase / # more stuff 

Leave a Reply

Your email address will not be published. Required fields are marked *