How to setup virtual host in wamp

I will demonstrate how to host more then one site on WAMP. I believe that WAMP is up and running on your window machine.

Suppose you want to host, say

  • localhost
  • my.localhost

We will consider all the file one by one that need to be modified:


Go to “C:/Windows/System32/drivers/etc” and open the “hosts” file in Notepad and add the following lines.

  •    my.localhost


Open “C:/wamp/bin/apache/ApacheX.X.XX/conf/ (X.X.XX denotes your apache version.)

Search for these two lines:

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

Remove “#” from second line above and save and close the httpd.conf file. This tells Apache to include the file “httpd-vhosts.conf”


Go to “C:/wamp/bin/apache/ApacheX.X.XX/conf/extra” and open the file “httpd.vhosts.conf”.

Add the lines to the file:

<VirtualHost *:80>
DocumentRoot “C:/wamp/www/”
ServerName localhost
ErrorLog “logs/localhost.log”
CustomLog “logs/localhost-access.log” common

<VirtualHost *:80>
DocumentRoot “C:/wamp/www/mylocalhost/”
ServerName my.localhost
ErrorLog “logs/my.log”
CustomLog “logs/my-access.log” common

DocumentRoot should map to the directory of the project that need to be accessed via web browser for particular host entry (i.e. where you code entry path exist.)

Also, if you need to serve the virtual host on a non-standard port, change it in the VirtualHost directive line.

After you add the above code to the correct file, save it and restart your WAMP services. Now you should be able to see both localhost and my.localhost from your browser.