How to Properly Virtual Host in WAMP 2


In the past, I’ve done some minor hacking to the WAMP 2 configurations to enable vhosts. Today, I noticed a new change on my default localhost for it. Above the Alias list, there is a header titled “Your Virtual Hosts”. This definitely perked my interest as WAMP 2 had previously a lax support for a feature I use dearly. (Y U NO VHOST?)


The first place I started to look at was the default index.php file.

What does this do exactly? It reads through the $vhostsDir and finds all the files that have ‘.conf’ in them, then lists the filename without ‘.conf’ in a list. (IE. localhost.conf becomes http://localhost)

So now you’re probably intrigued by this built-in feature, so how well does it work? Sadly… It doesn’t seem to be fully implemented yet. Not to fear, I’ve got a solid workaround to make it work as intended.

Open the wamp/bin/apache/Apache*/conf/httpd.conf file and add this at the very bottom under Aliases:

Then create a folder named ‘vhosts’ in the wamp root. (For myself, that was C:Wampvhosts). Within it, create a file named ‘localhost.conf’ and fill it in with this Apache configuration:

<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot "c:/wamp/www"
ServerName localhost

That’s it! Now edit your C:WindowsSystem32driversetchosts file to point the domain names to localhost, create a conf file for your new domain, and restart WAMP.

Published by

Joel Larson

Joel Larson has roughly twenty years of experience developing in web languages. He specializes in PHP development, general hacking, music critiquing, and evolving ideas.

3 thoughts on “How to Properly Virtual Host in WAMP 2”

  1. Nice one Joel. This is much better than having all the virtual hosts at the bottom of httpd.conf . Maybe we will never know why the page’s original author chose not provide instructions?

  2. Observation and recommendation:

    The approach advocated above causes individual c:/wamp/vhosts/ files to be included in alphabetical filename order, (where filename should be equal to ServerName in each case) causing the VirtualHost for “localhost” not necessarily to be the first listed, which is (typically) undesirable due to Apache’s “best match” rules for unspecified IP:port combinations.

    Therefore, it’s (typically) better to leave the vhost for “localhost” in httpd-vhosts.conf (or httpd.conf) in preference to having a “c:/wamp/vhosts/localhost.conf” file. Thus it can be guaranteed that the vhost for “localhost” is the first vhost specified in the fully expanded “httpd.conf”, when all the including is complete.

    By doing this, localhost becomes the preferred “best match” in cases where there are multiple identical “best matches” of IP:port.

    Of corse, the omission of a “c:/wamp/vhosts/localhost.conf” file will cause “http://localhost” not to appear in the “Your Virtual Hosts” list, but this is typically not an issue (by definition, if you are viewing the list then you are already browsing localhost’s index page). If for any reason, you need “http://localhost” to be listed, then other approaches are available, notably specifying a “_default_” vhost for one or more ports, as required.

    I would recommend departing from the above approach only if you really know what you are doing.

    These and related issues are exaplained here:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">