Mon, 15 Dec 08

A Utility to Manage Apache Virtual Hosts on a Mac (Like the Passenger Pref Pane but for Simple Static Sites)

29 Jun 2009. See the updated post about this utility.

I really like the Passenger preference pane, for both its functionality and simplicity. I wondered whether there was anything similar that would allow me to create simple virtual hosts in the same way (i.e. create the apache config and register the hostname with directory services). I saw mention of something called headdress (that supposedly makes apache config easier) but the site’s been down for the last couple of days and I believe it’s pay-for software anyway. I decided to steal the concepts (and the code for the dscl stuff) from the passenger pref pane code and create a little shell script that allows me to manage virtual hosts on my Mac.

You can get it by checking out the source:

svn co

It works in a very similar way to the Passenger preference pane: you give it a domain and directory (sudo apacherb create chrisroos.local /path/to/chrisroos.local) and it’ll create the necessary config (in /etc/apache2/apacherb_vhosts/) and register the domain with directory services. You can also delete (sudo apacherb delete chrisroos.local) and list (apacherb list) these vhosts. Just execute the script to see the help message (or look at the code).

I use this script to generate apache virtual hosts, instead of using the built in webrick server, for my webby sites so that I can see them exactly as they’ll appear when they’re deployed.

I’d be interested to know if this is of use to anyone else and if there’s anything else you’d like to see it do.