To create multiple websites, it would be helpful to have each website setup on the local computer. With Wampserver (or just Apache) we can easily configure multiple websites. Following are the steps to create multiple websites using Apache’s configuration. This uses Apache’s “Named Virtual Hosts” configuration. I have tested these steps on Wampserver 2.1 running on Windows XP and Windows 7.
Step 1: Set your hostnames or setup Windows to recognize your local websites
After installing WAMP server you can go to the browser and type http://localhost and it opens up a page. Windows by default recognizes the site localhost as referring to itself. We need to setup windows to recognize our other local websites. To do this we need to edit the
hosts file. This file is found under the following directory. (Another way to reach this directory is, open the run command or press Windows Key + R, and then type “drivers” and press “OK” then go to “etc”.)
After going to this directory open the file named
hosts in this directory using your favorite texteditor (like Notepad, Editplus, Notepad++).
Note: You may not be able to edit or save this file in Windows Vista or Windows 7. You need administrator rights to edit this file.
Now, you would see a line at the end of the file follows:
This code tells your computer to connect to your own computer when we try to go to http://localhost
Now we should add our site to this file. Lets say our site name is site1. So we would add an entry for it in the
hosts file. The updated file would look similar to the following:
127.0.0.1 localhost 127.0.0.1 site1
Note: Make sure you do not add host entries for external sites like google.com or bing.com. If you add these entries, then the computer would no longer be able to go to the actual websites.
Step 2: Create a folder for the website
Wampserver has only one folder or site root to host the website. This folder is typically
C:/wamp/www. We should create a different folder for each website. We can create the folder in any directory or drive. (If we create the folder outside of
C:/wamp/www we would need some additional settings in Apache described later).
Add some test file in this folder like “index.html” in say
Step 3: Setup Apache to serve multiple sites
We would change the file
httpd-vhosts.conf for the Apache setting.
Open the file
httpd.conf by clicking the WAMP server icon and selecting “Apache -> httpd.conf”. This file is typically located at
Don’t add code to this file, its not a clean and easy way. We just want to un-comment one line in this file that include the vhosts file.
Remove the # sign from the front of the line, the changed line should look as follows:
Now, we will open the file “httpd-vhosts.conf”, which would be typically located inside the extra directory (
In this file we will add virtual host using the following code:
<VirtualHost *:80> ServerAdmin admin@localhost DocumentRoot "C:/wamp/www" ServerName localhost ServerAlias www.localhost.com ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common </VirtualHost>
In the above code the ServerName and DocumentRoot are mandatory, other options are optional.
So if we want to have 3 sites on our local machine as follows
localhost -> C:/wamp/www
site1 -> C:/wamp/www/site1
site2 -> C:/site2
<VirtualHost *:80> ServerAdmin admin@localhost DocumentRoot "C:/wamp/www" ServerName localhost ServerAlias www.localhost.com ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/wamp/www/site1" ServerName site1 </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/site2" ServerName site2 <Directory "C:/site2"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
I have not used all the options for site1 and site2, but it is a good practice to have them. Also notice that the code for site2 has some extra code for Directory. This is necessary to give the server access to that directory. If we don’t add this, the server will not be able to access the files in this directory and hence the site would not work. We don’t need this for site1 as its inside
C:\wamp\www directory for which the directory setting are set by defult in wampserver.
Now restart Apache and all your sites should be working. Make sure you add site2 to your hosts file and create the directory for it at
Note: I do not take responsibility for proper functioning of the above mentioned steps under all circumstances. If you download any files, programs from my blog then make sure you protect yourself. I am not responsible for any damages to your computer, website, blog, application or any thing else. I am not affiliated with or do not endorse any of the above mentioned sites.