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.
Hey, Nice beginning.. sloppy ending… where is that etc/hosts file that you mention on the sly in the end????
i got half way or maybe 2/3 of the way but you left me/us hanging…
I’m new to the whole setting up apache with terminal etc. and I’m sure I’m not alone, so do you mind elaborating on the last part of your otherwise excellent tutorial
Thanks
L
/etc/hosts is the file. The /etc folder is hidden in Finder so you have to use the Go to Folder command (Cmd-shift-G) to get there. Or you can hit Cmd-shift-G in the Open dialog of your text editor.
Hope that helps!