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”.)
“C:\Windows\System32\drivers\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:
127.0.0.1 localhost
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
Save this file and try going to http://site1
This would take you to the same page as http://localhost
Now our computer knows what http://site1 is.
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 on 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 “C:\wamp\www\site1″ directory.
Step 3: Setup Apache to serve multiple sites
We would change the file “httpd.conf” and “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 “C:\wamp\bin\apache\Apache2.2.17\conf”.
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.
#Include conf/extra/httpd-vhosts.conf
Remove the # sign from the front of the line, the changed line should look as follows:
Include conf/extra/httpd-vhosts.conf
Now, we will open the file “httpd-vhosts.conf”, which would be typically located inside the extra directory (“C:\wamp\bin\apache\Apache2.2.17\conf\extra”)
In this file we will add virtual host using the following code:
ServerAdmin adminc@localhost
DocumentRoot “C:/wamp/www”
ServerName localhost
ServerAlias www.localhost.com
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common
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
ServerAdmin admin@localhost
DocumentRoot “C:/wamp/www”
ServerName localhost
ServerAlias www.localhost.com
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common
DocumentRoot “C:/wamp/www/site1″
ServerName site1
DocumentRoot “C:/site2″
ServerName site2
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
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.
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 C:\site2.
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.
Like this:
Be the first to like this post.
Pingback: Enabling WebDAV On Fedora 16 | EssayBoard
Hi Virendra,
Wonderful and helpful post, thank you. In your example, can site2 be on a different local disk like D:/site2?
Eg.
localhost -> c:wampwww
site1 -> c:wampwwwsite1
site2 -> d:site2
—————————————————————————————-
ServerAdmin admin@localhost
DocumentRoot “C:/wamp/www”
ServerName localhost
ServerAlias http://www.localhost.com
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common
DocumentRoot “C:/wamp/www/site1″
ServerName site1
DocumentRoot “D:/site2″
ServerName site2
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
Hi Donna,
Yes, site2 can be on different disk as long as it is accessible by apache server.
Thank you for your reply Virendra, but what do you mean by as long as the disk is accessible by apache server? I assumed configuring C:wampbinapacheApache2.2.17conf and httpd-vhosts.conf as per your instructions would give apache access alread? What else would I have to do then to make Apache accessible to my D drive? Thank you for your help.
Yes, it should be accessible by apache. If the site is on different drives on same machine then you should not have any problem.
Would this be possible if the drive was on a different machine..? Method?
Ive read closely vhosts setup on here and on other sites and attempted several times, but keep making mistakes and as a result have had to take sites offline. I am not efficient with tech language and reading guidance notes on Apache site is just making me go blind. I fresh installed wamp with no changes to configs with view to starting from scratch. I have a business web in www folder and a personal web in a sub folder till I can work out what to do. I do use no-ip, and the web urls for each site do reflect the nature of each one (http://businesssite.serveblog.net and Personalsite.hopto.net) but obviously they both come through one router and one port 80 to one machine, and only Business site serves up.
My problem is that the basic setup of WAMP with my Business website in root folder and Personal website in subfolder means all image folders in the business and personal folders show up in the google search. I assume this is because the sites are served from the same machine. How do I serve a business website and a personal website through 1 router from separate machines or ip addresses? This is the only way I can think of to keep business files and personal files separately from showing up in google images when entering url from one site or the other.
Any advice would be most appreciated.