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:

host

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

  •  127.0.0.1    my.localhost

http.conf

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”

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>
ServerAdmin admin@domain.com
DocumentRoot “C:/wamp/www/”
ServerName localhost
ErrorLog “logs/localhost.log”
CustomLog “logs/localhost-access.log” common
</VirtualHost>

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

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.