Creating Multiple Sites on a Local Web Server
Posted on December 5, 2007 in Tutorial | 8 Comments »
So while I was redesigning my site, I needed somewhere to develop the new design. I didn’t want to have to setup a sub-domain on the live site because that would be a pain to have to FTP files up everytime I changed something. So I installed XAMPP on my computer.
Basically, XAMPP is a all in one Apache web server. It installs Apache, PHP, MySQL…everything I needed.
Once you install it, you get a web directory here C:\Program Files\xampp\htdocs (or whichever directory you install XAMPP to). That’s great, everything works fine when you put things in that directory and browse to localhost. But what about if you want to setup multiple sites? That is where I really had to do some digging.
Setting Up Multiple Sites
I found this really good article that walks you through setting up multiple sites on XAMPP. The article was a little longer than I thought it had to be, so I thought I would clarify some things.
- Find this file: C:\Program Files\xampp\apache\conf\extra\httpd-vhosts.conf, and open it in notepad.
- Find a line that says something like NameVirtualHost *:80. Remove the # sign that you see in front of it; this turns it from being a comment to code that is actually executed. (This was not in any instructions I could find)
-
Next, scroll to the bottom, and you can add multiple domains. Here is what mine looks like:
<VirtualHost *:80> ServerAdmin webmaster@localhost.trevordavis.dev DocumentRoot "C:/sites/trevordavis.dev/webpages" ServerName localhost.trevordavis.dev </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost.trevordavis.redesign DocumentRoot "C:/sites/trevordavis.redesign/webpages" ServerName localhost.trevordavis.redesign </VirtualHost> -
Finally, find this file: C:\WINDOWS\system32\drivers\etc\hosts and open it in notepad. You need to add an entry for each site you setup in the httpd-vhosts.conf file. My file looks like this:
127.0.0.1 localhost 127.0.0.1 localhost.trevordavis.dev 127.0.0.1 localhost.trevordavis.redesign
That’s It
Once you have done this you can browse to http://localhost.trevordavis.dev and http://localhost.trevordavis.redesign on your computer when you have your web server running. This means that you can view PHP files and execute SQL locally.
It’s great.
Let me know if you have any questions.

























Adrian TurnerDecember 15, 2007 at 8:15 pm
When i enter:
http://localhost.seeyouin1984.dev/
my site doesn’t load i just get another version of the page that lets you know the install was successful and the url changes to:
http://localhost.seeyouin1984.dev/xampp/
I there something I could have missed?
raghav mathurMarch 24, 2008 at 3:27 pm
NameVirtualHost 127.0.0.1
DocumentRoot “c:/site1”
ServerName http://www.yoursite.com
Order Deny,Allow
Allow from all
u missed the directory part to set permission jus add u will be oaky
Chilli KingMay 15, 2008 at 9:05 am
Trev, nice site, nice explanation but for the life of me i can’t get it to work!!!
I’ve got this in my hosts file:
127.0.0.1 localhost
127.0.0.1 localhost.chilliking
127.0.0.1 localhost.cycling
and this in my vhosts.conf file:
DocumentRoot “E:\xampp\htdocs\cycling”
ServerName localhost.cycling
DocumentRoot “E:\xampp\htdocs\chilliking”
ServerName localhost.chilliking
When I browse to http://localhost.cycling/ or http://localhost.thechilliking/ i get the following error:
Could Not Connect to Server
Webwasher was not able to connect to localhost.cycling.
If you would like to try again, click here.
Interestingly when i try to browse to http://localhost/ i can view the cycling site no problems. The only way i can successfully view the chilli site is o switch the order of the entries in the vhosts file. i .e. change the text above to :
DocumentRoot “E:\xampp\htdocs\chilliking”
ServerName localhost.chilliking
DocumentRoot “E:\xampp\htdocs\cycling”
ServerName localhost.cycling
Any ideas???
TrevorMay 15, 2008 at 9:14 am
@Chilli King-
Did you find this line NameVirtualHost *:80? By default, it should be commented out (# at the beginning of the line). Make sure you un-comment that line.
Chilli KingMay 15, 2008 at 9:29 am
thanks for the reply. i’ve uncommented that line so now i have:
NameVirtualHost *:80
VirtualHost *:80
DocumentRoot “E:\xampp\htdocs\chilliking”
ServerName localhost.chilliking
/VirtualHost
VirtualHost *:80
DocumentRoot “E:\xampp\htdocs\cycling”
ServerName localhost.cycling
/VirtualHost
unfortunately i still get the same behaviour….nothing unless i just browse to http://localhost, where i can then view whichever site comes first in my vhosts file.
Any other ideas?
Chilli KingMay 15, 2008 at 10:20 am
Hi - just managed to solve the problem thask to this thread:
http://forums.whirlpool.net.au/forum-replies-archive.cfm/569991.html
TrevorMay 15, 2008 at 10:23 am
@Chilli King-
Great! What was the issue you were having and how did you solve it?
2 sites on XAMPPMay 15, 2008 at 11:33 am
not sure exactly what my problem was howevr here is exactly what i did:
If you are having a problem setting up multiple web sites using XAMPP try the following process:
Assumptions- root folders for your two sites are:
c:/mysite/
c:/myweb/
1) add these lines to the Windows Hosts file
127.0.0.1. myweb
127.0.0.1. mysite
2) Into Apache’s “\xampp\apache\conf\Http.conf” file add the following:
<Directory c:\myweb>
Order allow,deny
Allow from all
</Directory>
<Directory c:\mysite>
Order allow,deny
Allow from all
</Directory>
3) Add this is the “\xampp\apache\conf\extra\httpd-vhosts.conf” file:
<VirtualHost *:80>
ServerName myweb
DocumentRoot C:\myweb
<Directory C:\myweb>
IndexOptions +FancyIndexing NameWidth=*
Options Includes FollowSymLinks Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mysite
DocumentRoot C:\mysite
<Directory C:\mysite>
IndexOptions +FancyIndexing NameWidth=*
Options Includes FollowSymLinks Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now open a browser and simple type either myweb or mysite and you should be able to see both of your site wih all the php in their full glory!