Configure Virtual Hosts in WAMP Server (MS Windows)

Fri, 11/02/2012 - 14:34 -- Arisen

I use wamp a lot for configuring and installing sites locally first to do testing on different applications before running them on production servers. So the problem I run into a lot is remembering the urls for these different sites. So now I use virtual hosts and setup alias to the different urls. If you have two sites (site1 and site2) locally, it’s always a pain having to browse them by using “http://localhost/site1/index.php” as a URL.

The best way is always to make the URL shorter and for this WampServer allows you to create Virtual Hosts. The general idea of Virtual Hosts is that you can use something like “http://site1″ or “http://site2″ instead of having to use the complete URL.

Edit the http.conf file

Under C:\wamp\bin\apache\Apache2.2.21\conf\http.conf uncomment the following line to include the httpd-vhosts.conf file:

# Virtual hosts 
Include conf/extra/httpd-vhosts.conf

Define your Virtual Hosts

In wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf adding the following:

# Virtual Hosts
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
# Please see the documentation at 
# for further details before you try to setup virtual hosts.
# You may use the command line option '-S' to verify your virtual host
# configuration.

# Use name-based virtual hosting.
NameVirtualHost *:80

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.

    ServerAdmin webmaster@localhost
    DocumentRoot "c:\wamp\www"
    ServerName localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
		Options Indexes FollowSymLinks 
		AllowOverride all 
		Order Deny,Allow 
		Deny from all 
		Allow from 

    ServerAdmin webmaster@newsite
    DocumentRoot "c:\wamp\www\newsite\htdocs"
    ServerName newsite
    ErrorLog "logs/newsite-error.log"
    CustomLog "logs/newsite-access.log" common
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride all 
		Order Deny,Allow 
		Deny from all 
		Allow from 

Add your virtual hosts to the local windows hosts.conf

Edit the file located in C:\WINDOWS\system32\drivers\etc\hosts and make sure the program you are running is in administrator mode in order to save the changes correctly.    localhost    newsite

Restart Wamp

Once you've restarted wamp you should now be able to navigate to http://newsite and show any pages you have saved there.