Digital Media Insights for Business Owners

How to Setup Virtual Hosts, MAMP – Mac OS X

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:

# <directory "="" pathtoyourrootdirectory="" pathtoyoursitesfiles="">
#	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

Say: "Hola" to your new clients.

Follow us on Social Media for more Tips & Tricks.

Other Posts You May Enjoy