I have decided to start playing around with the Zend Framework. I have a web host (of course) however sometimes when developing I find it is easier and faster to use a local web server, with all the bells and whistles. WAMP, LAMP (this link is ubuntu specific, but any linux distribution should have easy HowTo guide for installing the LAMP software stack), MAMP, all provide the basic environment for beginning web development, and some have nice little GUIs to help you configure and maintain your local web server.
So for this tutorial I am going to show you how to add multiple virtual hosts to a WAMP installation. I am using the latest version from their website at the time this article was written. I installed WAMP, and left all defaults when going through the install wizard. I then launched WAMP and a nice little “odometer” icon appears in the System Tray, and cycles through 3 phases. As is starts the services (MySQL, and Apache) it cycles through the phases, and when you only see white (with some black) then all services started successfully. The little Lock in the middle of the icon means that the webhost is in private mode, so if your on an internal network, this means only you can view the website, and not somebody else. But if you want another user to see your webpage (perhaps a co-worker on another computer), you can then simply Left Click the icon and choose “Put Online”.
So now that WAMP is installed you can browse to http://localhost and look at your WAMP dashboard.
This is great, and we can choose the option to put all of our projects or development sandboxes in the “Alias” part of apache, but then each address would be http://localhost/MYALIAS which is bland. We want to make our own local URLs link http://MyAlias, so we can host multiple projects locally each with unique domain names. So we have to get apache to do so. Follow the instructions below to accomplish this.
First lets edit the windows hosts file located in C:\Windows\system32\drivers\etc\hosts. Open up the file in your favourite text editor and add a line like 127.0.0.1 your-local-domainYou can put any name in place of your-local-domain, just be sure to change it everywhere it is mentioned in this guide. Your file should look something like mine does in the picture below.
Now you can save that and close your text editor. Next we want to edit our httpd.conf file and httpd-vhosts.conf file. So first browse to C:\wamp\bin\apache\apache2.2.8\conf and open up httpd.conf in your favorite text editor. Then scroll down to the bottom. Look for this line Include conf/extra/httpd-vhosts.conf and uncomment it. Your file should now look like the picture below. Save it and close your text editor.
Now guess what file we are going to edit next? The include file we just uncommented of course. So now browse just one more folder down the tree to C:\wamp\bin\apache\apache2.2.8\conf\extras and open the in your favourite text editor once again. Now scroll to the bottom and add this code Save the file and close your text editor. Now all that’s left is to restart apache, which can simply be done by left clicking the little wamp odometer, and clicking “restart all services”. Done, now you can go to http://your-local-domain and you will probably get a 404 page not found error, but throw an index.html in the folder and it should work like a charm. Enjoy!
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "c:/Users/marf/Projects/your local folder/html"
ServerName your-local-domain
ErrorLog "logs/your_own-error.log"
CustomLog "logs/your_own-access.log" common
<directory "c:/Users/marf/Projects/your local folder/html">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
Now let me explain. The first

Just an FYI– I fought this for a while and then realized that my /’s should be a \ because i was in windows… all is well now
Commenting on your FYI, I did this in windows as well and had no problem leaving the /’s as /’s.
I also use virtual host, but despite the “Deny from all” the virtual host is all open to every one.
Seems that apache isn’t taking that rule?
Curious, does your little WAMP system tray icon have the little Lock on it or not? If it’s not there, then I believe it is in “online” mode, and so anybody can view your web pages.
Marf: It is offline (wamp only add/removes the Allow from line in the http.conf)
Oops…. just copying the VH to this box and suddenly I see it…. Directory directive was not the same as the DocumentRoot.
Solved
I am able to share my local site with my co worker but only one person at the time then I see your “howto” now either I got fobidden or no page display. Seriously if it is in Windows should be “\s” instead “/s” also when you state document like this
DocumentRoot “c:/Users/marf/Projects/sandbox/html”
How do I approach this?
In your folder sanbox do you anything.html? can I say .htm?
Please help. I need to be done by Monday.
Excellent! Thanks Big big!
Thanks for the great tutorial, it is very clear and easy to follow with the screen shots!
I tried it on Vista and when I put in subdomain.localhost, it kept bringing up the same page as just localhost, it wasn’t accessing my subdomain site. I had to change the second VirtualHost a little to put in your-local-domain:
ServerAdmin webmaster@localhost
DocumentRoot “c:/Users/marf/Projects/your local folder/html”
ServerName your-local-domain
…
I restarted the Wamp services and now it works
Olivier, if you could be more specific as to where you added that, because I don’t see how that is different than what I have above.
Thanks
Thanks for the article. I was having trouble accessing the dashboard after adding my local domain. Going to localhost would load my localdomain site. Making sure the virtual host entry for localhost came before my localdomain took care of the issue.
Hey, This is the best tutorial on WAMP virtual hosts on the web. I should know, I tried and failed with several others. Perhaps it was because the other tutorials were for an earlier version of WAMP and I have WAMP 2.0 installed?
Thank you so much for taking the trouble to put such a well explained and illustrated tutorial online. I am now hosting multiple local sites.
Well done.
Thanks! I reviewed four or five other sites before finding yours buried deep in Google results. I’ll share this with others.
Thanks for this awesome tutorial!
I installed WAMP on my machine for the first time yesterday after years of working online. Following your tutorial was completely painless and I’ve now managed to set everything up so I can access all my sites on a separate hard drive where I’ve had them stored - awesome job!
Thank you, this is exactly what I needed
Thanks, it works for me. Thank you very much.
Wow, thank you so much for this post!
I just upgraded from WAMP5 to WampServer 2.0 and my old virtual hosts no longer worked. I only had DocumentRoot and ServerName entries under WAMP5 but this doesn’t translate to WampServer2 without throwing 403 Forbidden errors.
Your tutorial was the only one I found that mentioned the entries. I added those and now my local sites have come back.
I wish I’d found your tutorial first, I’ve just wasted the last two hours reading others that have sent me completely on the wrong path!
Thanks again for saving me from losing more hair
Thanks, thats what i was looking for developing symfony projects at same time.
I seem to be having problems getting the www. to work as well as the tld. Any ideas?
My code seems identical to the code above
This was exactly the solution I was looking for.. worked perfectly. Thanks for putting it together.
Thanks so much for this, struggled through at least 6 other tutorials before trying yours which worked first time! thanks! though its worth noting for anyone trying this on earlier versions of apache that not all the files and lines are present.
I wanted virtual server up and running at the ealiest and so googled and tried to implement reading the tutorials - only this worked in mins. Thanks a ton.
Hi,
Thanks for the great tutorial. I have tried a few different easy install apache php mysql along quite a few tutorials trying to get virtual hosts working with limit success. Sounds like you had similar experiences. Your tutorial and WAMP has made my life a lot easier, and its the first tutorial thats made virtual hosts work properly while not breaking the localhost and the WAMP homepage on the localhost.
Well done.
Hi Thanks for the tut. I had virtual hosts running on WAMP5 no problem. But setting this up doesn’t work for me. FYI i completely uninstalled old WAMP and installed the latest version. I’ve done the changes and restarted all services, http://localhost works fine, displays the WAMP dashboard, but other domains cant be found. any ideas?
ServerAdmin webmaster@localhost
DocumentRoot “c:/wamp/www/”
ServerName localhost
ErrorLog “logs\localhost-error.log”
CustomLog “logs\localhost-access.log” common
ServerAdmin webmaster@localhost
DocumentRoot “c:/wamp/www/dom/www/”
ServerName dom.localhost
ErrorLog “logs\dom-error.log”
CustomLog “logs\dom-access.log” common
@henkedo same problem, here. Really pissed.
Leave Comment