Setting up virtual hosts in WAMP on Windows is easier than it sounds. Here is how to do it.
1. Install WAMP
Without this step, you most likely won’t have a hosts file to speak of.
And be forewarned: when you log in to phpMyAdmin, you will see a warning like this one:
“Your configuration file contains settings (root with no password) that correspond to the default MySQL privileged account. Your MySQL server is running with this default, is open to intrusion, and you really should fix this security hole by setting a password for user ‘root’.”
Don’t screw up your installation by following directions to set a password for the root user. Just stay away from this unless you really know what you are doing. (Clicking your way through the phpMyAdmin interface to fix the vulnerability would only result in phpMyAdmin losing access to MySQL and you starting from scratch, so please don’t, for now.)
2. Edit the hosts file on Windows
The hosts file on Windows (both 64 bit and 32 bit systems) is located in
[code]C:\Windows\system32\drivers\etc\hosts[/code]
Open this file in a code editor and add a line like this:
[code]127.0.0.1 webserver1.home[/code]
behind whatever other content is there already. Save and close the file.
3. Edit the httpd.conf file
In the Windows Explorer, navigate to
[code]C:\wamp\bin\apache\apache2.2.17\conf[/code]
and open the httpd.conf file in a code editor.
Scroll to the bottom of this file and once you find this line:
[code]#Include conf/extra/httpd-vhosts.conf[/code]
remove the comment sign (#). Save and close the file.
Now it’s time to edit your virtual hosts list.
4. Edit the httpd-vhosts.conf
Navigate to this directory
[code]C:\wamp\bin\apache\apache2.2.11\conf\extra[/code]
and open the file httpd-vhosts.conf in your code editor. Scroll all the way to the bottom of this file and remove all dummy virtual host entries (they didn’t hurt because the file wasn’t being loaded but now that you completed step 3 above you must get this right). Put instead this code in place:
[code]<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>
DocumentRoot “c:/wamp/www/webserver1”
ServerName webserver1.home
<directory “c:/wamp/www/webserver1”>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>[code]
The first of these directives is needed to preserve the dashboard. The second directive is your virtual host, for which you should now create the directory webserver1 specified above.
In order to create additional virtual hosts, repeat the steps concerning webserver1 for your webserver2, and so forth. Save and close the file.
5. Restart Apache and verify
After restarting Apache using WAMP Server you should be able to access http://webserver1.home using your web browser.
Leave a Reply