Menu
Create Custom Side Menus
Frodo's Ghost | Setting Up XAMPP for subdomains
36
post-template-default,single,single-post,postid-36,single-format-standard,eltd-core-1.0.1,ajax_fade,page_not_loaded,,borderland - frodosghost-child-ver-1.0.0,borderland-ver-1.2, vertical_menu_with_scroll,smooth_scroll,side_menu_slide_with_content,width_470,paspartu_enabled,paspartu_on_bottom_fixed,wpb-js-composer js-comp-ver-4.4.4,vc_responsive

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 "htdocs"
  ServerName localhost
  ServerAlias localhost
</VirtualHost>

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

<VirtualHost *:80>
  DocumentRoot "c:devsubdomainweb"
  ServerName subdomain.localhost
  ServerAdmin admin@subdomain.localhost

  <Directory "c:devsubdomainweb">
    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:WINDOWSsystem32driversetc

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:devsymfonyjobeetweb"
  ServerName jobeet.localhost
  ServerAdmin admin@jobeet.localhost

  Alias /sf "c:devsymfonyjobeetlibvendorsymfonydatawebsf"
  <Directory "c:devsymfonyjobeetlibvendorsymfonydatawebsf">
    AllowOverride All
    Allow from All
  </Directory>
  <Directory "c:devsymfonyjobeetweb">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Enjoy. And let me know how you go.

james
4 Comments
  • Thank you. Working well..

    September 20, 2010 at 12:31 pm
  • 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 6, 2010 at 1:29 pm
  • 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 6, 2010 at 6:58 pm
  • arthurg@hotmail.es
    Reply

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

    Thanks.

    February 8, 2011 at 12:40 am

Post a Reply to jamesmonkey@gmail.com Cancel Reply