First a note: On Tiger, Apache configs are stored in /etc/httpd. Make a copy of this if you’ve made changes to it on Tiger, and then just delete the folder to avoid future confusion. On Leopard they’ve moved to /etc/apache2/.
Open /etc/apache2/httpd.conf and:
Uncomment (remove the # from) line 461 so it reads Include /private/etc/apache2/extra/httpd-vhosts.conf.
Save and close /etc/apache2/httpd.conf.
Now open /etc/apache2/extra/httpd-vhosts.conf.
Make sure line 19, NameVirtualHost *:80, isn’t commented.
Comment or remove both VirtualHost example blocks at the end (everything from <VirtualHost *:80> to </VirtualHost>.
Save and close /etc/apache2/extra/httpd-vhosts.conf.
Next open /etc/apache2/users/YOURUSERNAME.conf, or create it if it doesn’t exist. YOURUSERNAME is the short name as seen in your home directory.
Copy and paste the following:
<Directory "/Users/YOURUSERNAME/Sites/">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "/Users/YOURUSERNAME/Sites"
ServerName localhost
</VirtualHost>
If you want additional virtual hosts just add another block. For example I have a local WordPress installation that I want to access by simply typing “wp” in Safari:
<VirtualHost *:80>
DocumentRoot "/Users/justin/Sites/wordpress"
ServerName wp
</VirtualHost>
Save and close /etc/apache2/users/YOURUSERNAME.conf.
Lastly you need to add your virtual host names to /etc/hosts. It probably looks like this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
Add one line for each additional virtual host. For me that would be just 127.0.0.1 wp.
Turn Web Sharing off and on again from System Preferences > Sharing and you’re good to go.
I’ll be writing another one about running WordPress locally.
