Mac OS X Virtual Hosts on Leopard

I’ve been doing some work recently on a couple of websites (one being for Riverdale) and in order to test the sites I set up virtual hosting on the copy of Apache which came with Leopard. There’s a few tweaks/issues with Leopard’s Apache which I thought I’d write down incase it helps anyone else, or helps me in the future when I forget what I did!

So to setup the virtual hosting you need to first change some details in /private/etc/apache2/httpd.conf. You should make sure that the line for the virtual host module is not commented out:
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

Then, at the bottom of the file, add in the following:
Include /Users/username/Sites/vhost.d/*.conf
Where username is your own username.

Then you should create the directory /Users/username/Sites/vhost.d and into it, put these two files:
00_default.conf:
NameVirtualHost *:80
<VirtualHost *:80>
   DocumentRoot /Users/username/Sites/
</VirtualHost>

01_virtualsite.conf:
<VirtualHost *:80>
   ServerName virtualhost1
   DocumentRoot /Users/username/Sites/virtualhost1/
   <Directory "/Users/username/Sites/virtualhost1">
      Options +ExecCGI +Includes +FollowSymLinks
      AllowOverride All
   </Directory>
</VirtualHost>

Again, where username is your username.

Then, in /private/etc/hosts you need to add:
127.0.0.1 virtualhost1

Restart apache and check out http://virtualhost1/ – it should work!

The big problem with Leopard is that you can ONLY share websites from your ~/Sites directory. It works though if you put a symlink in there to another directory (such as in ~/Documents), but keeping your vhost pointing to the directory in ~/Sites.

No Comments »

No comments yet.

RSS feed for comments on this post.  | TrackBack URL

Leave a comment