Icon

Following the Footsteps of Heros, Never Lead to the Straight and Grey Roads. (Oh, Sleeper)

Frodosghost

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.

Include conf/extra/httpd-vhosts.conf

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

Uncomment the line:

NameVirtualHost *:80

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”:

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

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

<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>

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:

C:\WINDOWS\system32\drivers\etc

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:

127.0.0.1       subdomain.localhost

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:

<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>

Enjoy. And let me know how you go.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Netvibes
  • NewsVine
  • RSS
  • StumbleUpon

Category: Web Programming

Tagged: , , , , , , , , , ,

Leave a Reply