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.
Then navigate into [XAMPP]/apache/conf/extra directory. Open up httpd-vhosts.conf. Virtual hosts configured in here.
Uncomment the line:
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 email@example.com <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:
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:
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.
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 firstname.lastname@example.org 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.