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.
//chemin jusqu'aux fichiers vhosts
$vhostsDir = '../vhosts/';
$vhostsContents = '';
// recuperation des vhosts
while ($file = readdir($handle))
if (is_file($vhostsDir.$file) && strstr($file, '.conf'))
$msg = '';
$vhostsContents .= '<li><a href="http://'.str_replace('.conf','',$file).'/">http://'.str_replace('.conf','',$file).'</a></li>';
$vhostsContents = $langues[$langue]['txtNovhosts'];
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:\Wamp\vhosts). Within it, create a file named ‘localhost.conf’ and fill it in with this Apache configuration:
That’s it! Now edit your C:\Windows\System32\drivers\etc\hosts file to point the domain names to localhost, create a conf file for your new domain, and restart WAMP.