How to Create a Subdomain on WAMP
As a web developer first step to build a web application is setup the environment for development on local machine. Which involves setting up virtual hosts for local application address. This post will walk you through the steps to setup subdomain/V-Host on Windows using WAMP.

In order to configure local subdomain on windows WAMP you must enable virtual hosts feature and load the virtual host alias module in WAMP apache. It will be explained in one of the steps, We will be implementing following steps to setup a subdomain/virtual host on WAMP.
- Add an entry to windows host file. This will look for domain on local machine.
- Enable Virtual Hosts and Virtual Hosts Alias Module in WAMP Apache.
- Add entries to virtual hosts file for our desired domains.
- Test the implementation.
Step 1. Add an entry in windows' hosts file
Open the hosts file and add an entry for your subdomain. On windows machine this file can be found in the following location:
c:\windows\system32\drivers\etc\
This file has no extension just "hosts" file. So you have to open it using notepad or any editor of your choice. It also requires Administrator permissions so open it using "Run as Administrator". Add the following lines at the end of file:
127.0.0.1 main-domain.com 127.0.0.1 sub-domain.main-domain.com
Leave the first line as it is where it says "localhost" instead add the content of above snippet to file. The first line from snippet above is for your main domain whereas second line is for your sub-domain. You can change the main-domain.com and sub-domain.main-domain.com to any domain of your choice, I am using it for this post as an example. What actually this file does? 127.0.0.1 is self referenced loop back IP. Whenever this IP is accessed it will reference the local machine to resolve IP address to a hostname. That means the operating system will search for the given hostname on the same computer for server instead of looking it up in configured DNS.
Step 2. Enable Virtual Hosts
After adding entry to windows hosts file its time to enable your virtual hosts and load virtual host alias module in httpd.conf file. The file can be found on the following location:
C:\wamp\bin\apache\Apache2.2.11\conf\
To open httpd.conf simply left click your WAMP Tray icon, move your cursor over apache, and choose the file httpd.conf in sub-menu.
After opening httpd.conf search for the following lines and remove the "#" from the beginning of lines then save and exit.
#LoadModule vhost_alias_module modules/mod_vhost_alias.so #Include conf/extra/httpd-vhosts.conf
Now that you are done pointing your domain back to your local machine open the "httpd-vhosts" file on the following location for WAMP:
C:\wamp\bin\apache\Apache2.2.11\conf\extra\
I have WAMP installed in c:\
Step 3. Add an entry for VirtualHost (Sub-domain)
After opening the file add the following lines for your main domain and sub-domain, save the file and exit. Its best to keep a backup of original file before making any changes.
<VirtualHost *:80> DocumentRoot "c:/wamp/www" ServerName main-domain.com ServerAlias www.main-domain.com </VirtualHost> <VirtualHost *:80> DocumentRoot "c:/wamp/www/sub-domain" ServerName sub-domain.main-domain.com ServerAlias www.sub-domain.main-domain.com </VirtualHost>
DocumentRoot is the directory where
files for given domain are stored in my case I have a directory
"sub-domain" inside of root direcoty "www".
ServerName is the domain name or subdomain name.
ServerAlias is an alternate domain which is usually "www" but we used it for our subdomain in second entry above.
Step 4. Test your subdomain configuration
After following the above steps you need to restart WAMP server, open your browser and enter main-domain.com and then sub-domain.main-domain.com. You should be able to see the www as root of main-domain.com and www/sub-domain as your sub-domain.main-domain.com.