Search
« CakePHP : Toggle a BitWise status field | Main | CakePHP :: Forgotten Password »
Wednesday
Sep162009

Setting Up XAMPP for subdomains

It has evaded me for many moons. Long time playing, waiting and researching - biding my time to get the subdomains happening locally. I have been looking at working on a Symfony tutorial as it is something I must learn - unsure if willingly yet. And I decided I must get this down before moving on.

I have XAMPP 1.7.0 installed (ed. I think I should update). And I installed it directly into C:/xampp - so depending on where you have it installed, adjust the directories accordingly. For the sake of the article consider [XAMPP] the path to where your xampp directory is installed.

It can be a bit scary to be playing with a file that can take your localhost down. So make sure the first thing you do is copy the httpd.conf file. Navigate your file browser to [XAMPP]/apache/conf and copy the file. I have mine named old.httpd.conf and leave it in the same directory.

Open the httpd.conf file into your text editor of choice. And make sure that the include for the httpd-vhosts.conf is not commented out.

[bash]Include conf/extra/httpd-vhosts.conf[/bash]

Then navigate into [XAMPP]/apache/conf/extra directory. Open up httpd-vhosts.conf. Virtual hosts configured in here.

Uncomment the line:

[bash]NameVirtualHost *:80[/bash]

Next add in a host for your localhost. Take into account the location of your xampp install. Also remember if you have spaces in the location, then you will need the "quotes":

[bash]<VirtualHost *:80>
DocumentRoot<!--DVFMTSC--> [XAMPP]\htdocs
## DocumentRoot<!--DVFMTSC--> "[XAMPP WITH SPACES IN LOCATION]\htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>[/bash]

Finally for the vhosts conf file you can add your subdomain:

[bash]<VirtualHost *:80>
DocumentRoot "c:\dev\subdomain\web"
ServerName subdomain.localhost
ServerAdmin admin@subdomain.localhost

<Directory "c:\dev\subdomain\web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>[/bash]

You can see that the location to the subdomain doesn't have to be inside the htdocs file either. A good way to keep your SVN and dev code separate on a machine.

Lastly we need to edit one more file. I am on a Windows 32bit XP installed computer, so the file I was looking for was in:

[bash]C:\WINDOWS\system32\drivers\etc[/bash]

First, make a copy of the hosts file. It is always great to have backup if the fan is hit by digested food. After backing it up, open it in your text editor and add the line:

[bash]127.0.0.1 subdomain.localhost[/bash]

Just add it below the existing localhost one. Then it is just a matter of rebooting your localhost, either through the SCM or the XAMPP control panel.

Bonus Points


As I mentioned at the start I have been following along to a Symfony tutorial - Jobeet. On the first day it mentions setting up a test site, and that is why I got all this subdomain stuff together. So below is the subdomain setup in my httpd-vhosts.conf file:

[bash]<VirtualHost *:80>
DocumentRoot "c:\dev\symfony\jobeet\web"
ServerName jobeet.localhost
ServerAdmin admin@jobeet.localhost

Alias /sf "c:\dev\symfony\jobeet\lib\vendor\symfony\data\web\sf"
<Directory "c:\dev\symfony\jobeet\lib\vendor\symfony\data\web\sf">
AllowOverride All
Allow from All
</Directory>
<Directory "c:\dev\symfony\jobeet\web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>[/bash]

Enjoy. And let me know how you go.

Reader Comments (4)

Thank you. Working well..

September 20, 2010 | Unregistered CommenterIvan

Followed your instructions to the letter but its still not working. I'm getting a 404 whenever I try to go to the subdomain in my browser.

could it be the wildcard in NamrVirtualHost *:80?

December 7, 2010 | Unregistered Commentermandrill

Hi Mandrill,
It could be the wildcard, but usually it would not be. I am more specific when I set these up now just to restrict access better.

I would have to see what you have entered. If you still don't have it send me an email (on this page :: http://frodosghost.com/about/) and we'll see what we can sort out.

Regards.

December 7, 2010 | Unregistered CommenterJames

Excellent, but how can i access the xampp subdomain from another computer in the same network?

Thanks.

February 8, 2011 | Unregistered CommenterArthur

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>