30 Oct 2009

Apache Virtual Hosts (XAMPP)

apache

I had to create a couple virtual hosts on a windows 7 machine running XAMPP for development purposes.  This is typically a simple task.  XAMPP has an Apache virtual host configuration file in <xampp installation>\apache\conf\extra\httpd-vhosts.conf

There are some basic containers already set that you can use as reference, but in the end you have something like this:

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
	DocumentRoot D:/www
	ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1:80>
	DocumentRoot D:/www/mysite
	ServerName mysite.dev
</VirtualHost>

You then just configure your hosts file to point to your local IP address:

127.0.0.1    localhost
127.0.0.1    mysite.dev

You can add more directives to the virtualhost, but this was just the basic setup to get urls working without having to use subdirectories like http://localhost/mysite. Instead, I can use http://mysite.dev.

Restart apache and everything should be golden, but no, never quite that easy. I kept getting a blank screen for mysite.dev, but localhost was working. I would ping mysite.dev and get 127.0.0.1 like I would expect.

Well, long story short, I’ve behind a proxy/firewall and didn’t tell my browser to ignore the .dev domain. So, for my own purpose when I forget this again in a year or so, or anyone else behind a corporate network that may have a similar issue, this was why.

Leave a Reply