Dave Shea on Virtual Hosts
Nerd Alert! I learned a neat trick involving Apache virtual hosts and the Etc/Hosts file recently. Fortunately for you (and sad for my ego), Dave Shea beat me to writing a great post on this topic. The kicker for me was the Hosts file trick, which I learned from my friend Jorge just a week or so ago. That's what had inspired me to get all ready to blog about it before I saw Dave's entry. But now I figure, "Hey, what the heck!"
I implemented this idea on my home computer so dev.philsown.org is mapped to the local web server. I can set up other sites I am developing this way, so they each get their own page root and I'm not stuck trying to keep track of files in a subdirectory. This way I don't have mapping issues or have to write code to say "if we're on the development server, use this web root, if we're on the live server, use a different web root" (it is easy code to write, but why bother?).
On Winders X-Perience, edit C:\Windows\System32\Drivers\Etc\Hosts and add a line for the name of the virtual host you set up in Apache. In my case, I add:
127.0.0.1 dev.philsown.org
Update: I had this backwards previously. It's IP address followed by host name. And if it doesn't work right away, try in a command line:
ipconfig /flushdns
And you should get:
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.
It's interesting for me to note that since I have installed several a couple of anti-spyware programs, my Hosts file was full of entries for various ad servers all pointing to localhost. This keeps me from seeing ads when I surf the net. Using the Hosts file to remap domains is a clever trick with multiple uses if one is creative.
Trackback: http://philsown.org/2004/08/dave-shea-on-virtual-hosts/trackback
Comments
How to Put Your Face Next to Your Comment