WAMP - Multiple Roots Using Virtual Host
Ever since I first downloaded WAMP and started using it for all my web development needs (local development), I have wanted the ability/know-how to create multiple root directories. The reason being that I like to develop using root relative URL's. After a bit of digging around, I found a forum post that described how this could be accomplished using a Virtual Host. Unfortunately, after following the instructions exactly as they were stated in the forum post, I was unable to get the Virtual Host working. However, after more research and some tinkering, I was eventually able to get a second root directory working on my local WAMP install. To set up your own, just follow these instructions.
Step 1 - create directories:
- Open up the www folder installed by WAMP (For example mine is at c:\wamp\www\).
- Inside of this www folder implement the new directories (folders) shown below:
c:\wamp\www\roots\website1
c:\wamp\www\roots\website1\logs
c:\wamp\www\roots\website1\public_html
Step 2 - configure httpd.conf:
- Open the httpd.conf file in a text editor.
- Search for the "Listen 80" and add "Listen 81" right below it. Make sure that "Listen 80" does not have a "#" in front of it.
- Now search for "#NameVirtualHost *:80" and add "NameVirtualHost *:81" right below it.
- Now below the text you just added, add this chunk of text:
<VirtualHost *:81>
ServerName localhost
DocumentRoot c:\wamp\www\roots\website1\public_html
ErrorLog c:\wamp\www\roots\website1\logs\error.log
CustomLog c:\wamp\www\roots\website1\logs\access.log common
<Directory c:\wamp\www\roots\website1\public_html>
Options Indexes FollowSymLinks Includes
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost> - Save and close the httpd.conf file
- restart WAMP
Step 3 - test it out:
- Place an index.html file in the public_html ( c:\wamp\www\users\website1\public_html) folder. (Make sure it accesses another file (maybe a js file) using a root relative path.) Now open http://localhost:81 in a web browser. If you didn't already know, attempting to access localhost:80 will take you to the default WAMP page.
If the mouse pointer changes to a hand when you roll-over an image associated with a story the image upon clicking either links to enlarged version of the image or a website associated with the image.
Thanks, Cody.
A few comments later in that thread talk about some security concerns. I’m a newbie about server configuration; just wondering if you knew about/overcame that question?
Looking forward to seeing you again at SXSW...
@Michael – Well, to be honest, I did not pay attention to those concerns because I am behind a corporate network. My server is running locally only.
FYI follow-up:
These methods worked for me, without the port 81:
http://www.mezzoblue.com/archives/2004/08/05/virtual_host/index.php
http://www.thewatchmakerproject.com/journal/378/virtual-hosts-and-the-proper-way-to-work-offline
http://www.apptools.com/phptools/virtualhost.php
Basically involves editing the Windows hosts file as well as creating the Apache .conf file.
I only mention all three because they all corroborate each other.
@Michael – Thanks, I’ll give those a look.
I have been trying to figure this out for hours now using this method and have had no luck. I am running a development environment locally and need to use this for each of my client sites so I can write root relative URL’s also.
My problem is that my httpd.conf file doesn’t have this line:
#NameVirtualHost *:80
...although it does have this:
ServerName localhost:80
Which comes up after all the modules get loaded. I have tried variations of modifying this with no success.
My other problem is that I access the site on the machine running the server itself at localhost but from other computers on my network at 192.168.1.122. It seemed to be working a bit for a minute but I was getting different results based on which computer I was looking at the site from.
I also tried aliases and htaccess redirects with no luck either. I will continue looking into this problem but if anyone comes across this thread, you can reach me at my blog: dennisplucinik dot wordpress dot com.