As a web developer, I wanted a simple way to easily create and remove virtual hosts for Apple's built-in Apache server. The solution I've discovered allows me to create a virtual host just by creating a folder with the virtual hostname I want to use and editing my /etc/hosts file so that my browser will be able to find it. Removing the virtual host then is as easy as deleting the folder and the entry in /etc/hosts -- there's no need to edit Apache configuration files or restart Apache each time.
To set this solution up in Mac OS X 10.5.x, you'll need to edit two Apache configuration files, but you'll only have to do it this once. (Note that it's a good idea to make backups of your configuration files, just in case something doesn't work. I make no guarantees, nor am I responsible if you mess your system up!)
Here's what you need to do to get this working.
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /private/var/log/apache2/access_log vcommon
You will also need to comment out the following line, by putting a # at the beginning, as seen here:
#CustomLog /private/var/log/apache2/access_log common
When finished, that section will look something like this: (Note: For brevity's sake, I took out the explanatory comments):
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
#CustomLog /private/var/log/apache2/access_log common
#
# Logging virtual-host data with the common format
#
CustomLog /private/var/log/apache2/access_log vcommon
#CustomLog /private/var/log/apache2/access_log combined
</IfModule># Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# Mass Virtual Host configuration as taken from the Apache web documentation
#
<VirtualHost *:80>
# get the server name from the Host: header
UseCanonicalName Off
# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot "/Library/WebServer/Documents/%0"
VirtualScriptAlias "/Library/WebServer/Documents/%0/cgi-bin"
</VirtualHost>127.0.0.1 mysite.dev
The /etc/hosts file needs root privileges to modify it. I recommend using BBEdit or TextWrangler, as they will prompt you for your password to save the changes.Mac OS X Hints
http://hints.macworld.com/article.php?story=20081214054602993