How to Setup Virtual Hosts, MAMP – Mac OS X

September 20th, 2011 admin Location: Raleigh, NC, Topic: Web Design | Digital Media


So let’s say that you want to be able to work locally setting up a website instead of having to make all the changes in a remote server. This is often the case with beginner website developers. We’ve all been there so don’t feel bad. The usual thing is that you more of less develop the site and now you are pushing it live via a FTP client. But all of a sudden you want to change something and now you see yourself in this sea of downloads and uploads and it is certainly not working anymore. Plus, there is definitely a faster way right? You are right my friend, there is.

So finally you come about local development – local domains. Developing your websites locally in your machine and setting up a simple web server to make all the tests. That’s great. So you go about installing MAMP (MAC OS X, Apache, MySQL and PHP) and you have it working.

You got your parent folder set up and everything, however you may want at some point to be able to access your site with a virtual host name as opposed to having to type: http://localhost/mySite.

That’s where you are at. I’ll tell you what, there are some solutions out there that can do this for you and if you want to just go ahead and pay for one of them then you may not need to read any further. However, if what you want to do is to learn how to manually setup virtual hosts or virtual domains, then here it is.

The Solution:

There are two files that you are concerned with: 1. The hosts file and the httpd.conf file. This two files allow your Mac to know where to look for websites.

To get to the first file, simply open a finder window, then hit Shift, Command + G.

This is going to open the “Go to Folder” option of Finder. Then type “/etc”

That is going to take you to your /etc folder. Scroll down until you see the file called hosts.

This file is going to contain a set of value pairs that allow you to indicate to your Mac where you want to find a particular host. So for example, if it says that means that your computer instead of going out on the web and searching for the site it is going to look into your local host (address and then return whatever it finds there.

Now that is only part of the battle. You actually tricked your computer into believing that it should direct your search locally any time somebody types in a browser in your Mac. However, once localhost is reached it doesn’t know what to do with that request, because it doesn’t know that particular host. That’s what we are going to do next.

To setup a virtual host in your MAMP installation, you need to search for the httpd.conf file. You may find it by opening spotlight and searching for httpd – now make sure that the one that you find is the actual one being used by your local web server.

Open the file and then scroll to the bottom of the file where you will find the Virtual Hosts section.

Once there simply create a new directive for the webserver to know what to do when requested with here is how to do it:

Simply add the following lines of code to the end of your file:


#	ServerName ""
#	ServerAlias ""
#	DocumentRoot "/Users/username/pathToYourRootDirectory/PathToYourSitesFiles"
/*End of Code*/

And that is it. Now, make sure that you restart your MAMP webserver before you continue.
Then finally simply open up your browser and type and that’s it. If you followed this instructions properly you should see your local site.

Before I go I just want to let you know that this technique is very important because you save a lot of time developing locally and when you are finished just pushing your site live, as opposed to developing your site in a remote server. Time savings are always welcomed in our profession. Also you need to remember that professional developers are doing it this way and if you want to be a pro, you need to use their techniques.
Make sure to contact us if you have any questions on how to setup your local environment or if you need direction with your website project.
Believe me when I tell you, even though you may feel like you are the only one who doesn’t know how to do this, you are not alone, everybody has been in your shoes and they had to learn it.

I know that if you implement this simple steps you will be on your way to making better use of your time as a developer and helping your clients even more. If you took the time to read through this post what it means is that you are learning and growing and I want to congratulate you on that, not everybody is growing and wanting more, so you are way ahead.
Now go out there and use this, practice and remember to teach others as well.

Best of luck setting up your local domains

Alex Centeno MBA.
Creative Director & Digital Media Strategist
Merkados Interactive Partners[/private]

About the Author

Alex Centeno MBA., is an international creative director and digital media strategist. Currently residing minutes away from the Research Triangle Park (RTP) - North Carolina, and with over 10 years of interactive marketing training and experience, Alex leads Merkados' international clients to maximizing their online business strategies. One of Alex's biggest strengths is his world-class capacity to effectively combine interactive marketing, digital media design and web development.

You may find further information about Alex Centeno MBA. at: and Twitter.

Sobre el Autor

Alex Centeno MBA., Es un director creativo y estratega de medios digitales reconocido internacionalmente. En la actualidad reside a tan solo minutos del Research Triangle Park (RTP) - Carolina del Norte, y con más de 10 años de entrenamiento y experiencia en marketing interactivo, Alex lidera a los clientes internacionales de Merkados™ para maximizar sus estrategias de negocios en línea. Una de las mayores fortalezas de Alex es su capacidad global de combinar de manera efectiva, mercadeo interactivo, diseño de medios digitales y desarrollo web.

Para más información sobre Alex Centeno MBA. puede visitar: y Twitter.