Saturday, June 20, 2009

Setting up xampp for multi site serving on XP

The locations of the files you will need to edit.

[driveletter:]\xampp\apache\conf\httpd.conf (only if there is a permissions issue)
[driveletter:]\xampp\apache\conf\extra\httpd-vhosts.conf
C:\WINNT\system32\drivers\etc\hosts

See this for the official apache virtual host documentation if you get lost. I say that because every tutorial on the web told me to do that. I didn't in fact find it insightful specifically for this xampp setup.

Okay. On with the steps.

Create a new folder for your virtual hosts.

I created a new site folder under \xampp\1sites\ called newdevsite. I figure I'll access that folder quite a bit, so I added the '1' in front of it so it will float to the top of the folder listing.

Edit your hosts file to point your new virtual host to your local IP address.

Simply make a new line underneath the existing entry in the same format with your new development site.

I entered:

127.0.0.1 newdevsite

Edit httpd-vhosts.conf

Uncomment 'NameVirtualHost *:80' in httpd-vhosts.conf. Get rid of the "##".

I created the following two entries. From what I read, it's recommended to use forward slashes. It worked that way for me. If you want to continue using your existing site in xampp, you will need to add that as a virtual host as well.
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/xampp/1sites/newdevsite/public_html"
ServerName newdevsite
ServerAlias newdevsite
</VirtualHost>
Restart apache and test

If you get a 403 permissions error on the new virtual host

Once I got the VirtualHost directives correct, I was getting 403 permission errors on the newdevsite. (I don't know enough about apache administration, so to be safe I would footnote that I would not do the following on a live Apache installation).

The edit proposed by Preast in the following link straighted out the rest of my woes.
http://www.php-editors.com/forums/apache-help/2205-virtual-hosts-error-403-a.html (Copied text from that post below).

Did I mention I have no idea if this is a bad idea on a production server? The following is an edit to the httpd.conf file.

<directory>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all ## Changed this from "Deny from all" ##
Satisfy all
</directory>

Hijacking the live url of sites that use explicit URLs to themselves

If you are editing a site that is already live you could override http://thelivesite.com to point to your development location at 127.0.0.1 at every request.

Simply make an entry in the hosts file with 127.0.0.1 www.thelivesite.com

With this type of development environment set up and assuming you will be working with at least a few copies of live web sites, I would highly recommend getting notepad++ and leaving a copy of your hosts file open in it so you can tweak it on the fly.

2 Comments:

At June 25, 2009 4:01 PM, Anonymous Anonymous said...

Great tutorial PV!

 
At September 05, 2009 2:17 PM, Blogger Thomas Hunter II said...

Here is a guide if anyone needs more details...

http://renownedmedia.com/blog/setting-up-vhosts-using-xampp-or-apache-in-windows/

 

Post a Comment

<< Home