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 Filesxampphtdocs (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 Filesxamppapacheconfextrahttpd-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:WINDOWSsystem32driversetchosts 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.
Categories
Recent Articles
May 2012
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 |
10 Comments
Adrian Turner
12.15.2007When 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 mathur
03.24.2008NameVirtualHost 127.0.0.1
DocumentRoot “c:/site1”
ServerName www.yoursite.com
Order Deny,Allow
Allow from all
u missed the directory part to set permission jus add u will be oaky
Chilli King
05.15.2008Trev, 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:xampphtdocscycling”
ServerName localhost.cycling
DocumentRoot “E:xampphtdocschilliking”
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:xampphtdocschilliking”
ServerName localhost.chilliking
DocumentRoot “E:xampphtdocscycling”
ServerName localhost.cycling
Any ideas???
Trevor
05.15.2008@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 King
05.15.2008thanks for the reply. i’ve uncommented that line so now i have:
NameVirtualHost *:80
VirtualHost *:80
DocumentRoot “E:xampphtdocschilliking”
ServerName localhost.chilliking
/VirtualHost
VirtualHost *:80
DocumentRoot “E:xampphtdocscycling”
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 King
05.15.2008Hi - just managed to solve the problem thask to this thread:
http://forums.whirlpool.net.au/forum-replies-archive.cfm/569991.html
Trevor
05.15.2008@Chilli King-
Great! What was the issue you were having and how did you solve it?
2 sites on XAMPP
05.15.2008not 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 “xamppapacheconfHttp.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 “xamppapacheconfextrahttpd-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!
nert
05.25.2010how to open multiple websites that has been implemented on xampp via remote computers. I have try on local computer that has been installed with XAMPP and all websites running well on local computer. But when i try to open websites from others computer (via LAN network) it was failed, no error message just the page opening XAMPP page always, since our Document Root is on /xampp/htdocs. But when i change Document Root location, so i cannot open multi websites, only one websites that i filled the same location with Document Root.
Please let me know to solve this virtual hosts, so i could access all multi websites from others computer and the virtual hosts could work well.
Thanks a lot.
Regards,
NERT
——-
Nevada DUI Attorney
01.04.2011Ok Trevor. thank you so much for these instructions, first of all.
I’m trying to do 2 things, which is why I came here looking for these instructions:
1. redo my legal site and put it within drupal
2. build an online store, which uses nearly 100% all php files.
I have setup my databases for both, users for both. I have literally been doing the drupal site for a year. [yes I’m just that slow]
I recently started the ecommerce site, and low and behold no matter I do the drupal site comes up locally.
a. should I just uninstall the drupal site and start over?
b. or is there some way to move them around to be properly configured for the above instructions?
I apologize if I seem dense. I probably am.
So if I wanted my 2 sites to be named: DUI and Onlinstore “locally”. what might I put in these?
<VirtualHost *:80>
ServerAdmin .(JavaScript must be enabled to view this email address)
DocumentRoot “C:\xampplite\htdocs\My Online Store” [I guess this is right?]
ServerName dummy-host.localhost
ServerAlias www.dummy-host.localhost
ErrorLog “logs/dummy-host.localhost-error.log”
CustomLog “logs/dummy-host.localhost-access.log” combined
My biggest problem is I have no idea where the drupal stuff starts in xampp and don’t know where to separate them. I am not making the online store with drupal. I am thinking I didn’t setup the drupal to be isolated enough from xampp. It seems files and folders are located all over xampp’s original files.
[ I am slightly frustrated and thoroughly confused ]
Too late, comments are closed!
Don’t worry, you can email me or contact me on Twitter.