Virtual Hosts w/ MAMP

I recently had a need to add some virtual hosts to my local MAMP setup and while it was fairly straight forward I figured I would share some quick tips. For the purposes of this post I am assuming you are using the default MAMP settings including running Apache on port 8888. In this example I am building a new CodeIgniter installation and setting the document root to /Develop/CI.

First off let's go ahead and add an entry to our /etc/hosts file so that we can access the virtual host.

127.0.0.1 ci.here

The line above in the /etc/hosts file will allow you access your CodeIgniter install by visiting: http://ci.here:8888 but first we need to update our Apache configuration.

Next up we need to modify our httpd.conf file which in a default MAMP installation is located in: /Applications/MAMP/conf/apache/httpd.conf.

Now go ahead and start-up MAMP, everything should come up clean but if for any reason Apache doesn't start up then fire up a terminal window cd to /Applications/MAMP/bin and type the following.

sudo ./startApache.sh

Enter your password and boom, everything should be up and running and your newly created virtual host should be accessible.

For a more complex method which is particularly good if you are going to create multiple virtual hosts or want to run on the default port 80 I highly recommend this article.