Skip to content

Multiple virtual hosts in WAMP

Virtual hosting is a method for hosting multiple domain names on a computer using a single IP address. This allows one machine to share its resources, such as memory and processor cycles, to use its resources more efficiently. This is often found on shared hosting servers.

Developers often have loads of web sites under www or htdocs folder which are then accessed on daily basis. To be able to use absolute paths in your applications, some people change the documentroot variable in httpd.conf to current working directory. This allows them to access this page with just http://localhost.

But, it isn’t efficient because you have to change the variable manually, restart Apache, and it just takes to much time.

We can use Virtual hosts on Windows to deal with this problem. As I am using WAMP server for development, this tutorial will explain how to do it in WAMP, but other products are very similar, so you want have problems porting this.

First lets edit the windows hosts file located in C:\Windows\system32\drivers\etc\hosts. Open up the file in your favorite text editor and add a line like this:

[code lang=”html”] mydomain.home

Basically, this tells Windows to resolve IP (which is localhost) to mydomain.home. Save the file and close it.

Next we want to edit our httpd.conf file and httpd-vhosts.conf file. So first browse to C:\wamp\bin\apache\apache2.2.11\conf and open up httpd.conf in your favorite text editor. Then scroll down to the bottom. Look for this line:

[code lang=”html”]
#Include conf/extra/httpd-vhosts.conf

Uncomment it (remove the # symbol in the beginning of the line). Save the file and exit. Now browse just one more folder down the tree to C:\wamp\bin\apache\apache2.2.11\conf\extras and open the httpd-vhosts.conf in your favorite text editor. Now scroll to the bottom and add this code:

[code lang=”html”]

ServerAdmin webmaster@localhost
DocumentRoot “c:/wamp/www”
ServerName localhost
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common

DocumentRoot “c:/wamp/www/your-local-folder”
ServerName mydomain.home

Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from


There are two directives for Virtual Host. First one is preserving our localhost, so you can still access the WAMP dashboard. The second one is actually telling Apache where to look when someone requests mydomain.home . Rest of the entry is allowing you to use .htaccess on this domain.

Restart Apache server.

Now, you should be able to use http://mydomain.home to develop and test your site. Whenever you need to add new site just add new entry in Windows hosts file and copy last Virtual host entry in httpd-vhosts.conf and change the domain and path.

Now you know how to add Virtual Hosts under WAMP.

13 thoughts on “Multiple virtual hosts in WAMP”

  1. Doesn’t seem to work for me. Not sure what I put in hosts file for new site, have done everything in httpd-vhosts.conf as described, not working. I either don’t get resolved or it goes to another local site.

  2. Ah. You have to also uncomment in httpd-vhosts.conf the line that says NameVirtualHost *:80, then it works good.

    Thanks, very useful for me.

  3. Pingback: Multisite Drupal installation and virtualhosts « Jon Atxa's Blog

  4. The clearest, most concise post on this topic on the whole of the interwebs… can’t thank you enough!

  5. I stumbled upon your blog page this afternoon and its a extremely good useful read but the font seems a little off looking in firefox.

  6. Pingback: Front–end Developers Workflow: Windows/Ubuntu Edition | Gray Ghost Visuals Press

  7. FINALLY, a guide that makes sense, is easy to follow and doesn’t over-complicate what is essentially a simple process.

    Thanks so much!

Comments are closed.