Tutorial on setting up virtual hosts in Apache 2.2
Changes to the way Apache handles virtual hosts in the 2.2 series affect the instructions for setting up virtual hosts in Windows on pages 86-7 of Foundation PHP for Dreamweaver 8. The most important difference is that Apache 2.2 applies stricter permissions than either the 1.3 or the 2.0 series, so you’re likely to see a “Forbidden” message rather than the website that you were expecting. The other change is that the main configuration file, httpd.conf no longer contains everything under the sun. Virtual hosts and other optional features are now controlled by external files.
I’ve created a tutorial showing how to set up virtual hosts on Apache 2.2 in Windows. Although it was originally intended as an update for my book, I decided to give full instructions, rather than just outline the differences. As a result, the tutorial can be used even if you don’t have a copy of Foundation PHP for Dreamweaver 8. Although why anybody should be without a copy is one of the great mysteries of the universe.
If you haven’t experimented with virtual hosts in your local development environment, they’re well worth looking into - and they’re not difficult to set up. If you locate your testing sites in the Apache server root, localhost becomes the site root, and what should be the top level of the site goes in a subfolder. For simple sites, this doesn’t really matter, but it can make testing very difficult if you want to use links in PHP includes.
Root-relative links cannot be tested if the site is in a subfolder of the server root, but using a virtual host solves the problem. A virtual host gives you exactly the same structure in your testing environment as a live site because the top level folder of the virtual host becomes the testing site root. If you make extensive use of includes, virtual hosts are the way to go.
13 comments December 10th, 2006