Saturday, November 17, 2007

Virtual Hosts in Leopard

So, made the upgrade from Tiger to Leopard the other week. Migration went pretty well except for a few problems with apache. Since NetInfo Manager is now gone, my virtual host stuff was also gone. It might have been nice for the upgrade to have converted my NetInfo based host information into /etc/hosts for me, but it didn't. I like using virtual hosts for my development stuff, So I needed to fix that. There really isn't a way of doing this except in Terminal. But since I'm only adding one line, vi is pretty quick and painless.
sudo vi /private/etc/hosts
Ad a line similar to
127.0.0.1 random_bunny.dev
And you're done with that. No restarts required. Yay.

The next bit is that Leopard lost my old httpd.conf file. It did thoughtfully replace it with a default one that works, but it did turn a few things off and few things have changed. One of those things is that NameVirtualHost and the accompanying VirtualHost blocks have been moved out of httpd.conf and into httpd-vhosts.conf and some of the details are a bit different. The instructions in Virtual Hosts For Dummies are still essentially true. The differences are that :80 is at the end of the specifiers. Reading through the documentation, it seems like you can use the vhost file to specify other ports to serve content on, but I could be wrong. Anyway. I got things running by adding
NameVirtualHost 127.0.0.1:80

And to make sure that localhost still redirects to the right place:

<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>

And then for my development area:

<VirtualHost *:80>
DocumentRoot "/Users/random_bunny/Sites"
ServerName random_bunny.dev
</VirtualHost>

Uncomment the line in httpd.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf
Do a graceful restart and that bit works. Well, no, it doesn't. I kept getting 403 errors, even when trying to go through localhost. So I backed all my changes out and tried again. Still nothing. Time for google. I found this Mac OS X Leopard: Web Sharing Troubles: “Forbidden”. Apparently, a little thing that didn't work in the Leopard Migration is this. Migration Assistant doesn't copy or recreate /private/etc/httpd/users/ in /private/etc/apache2/users/, so it can't redirect things properly. Easiest way to fix this is
sudo cp /private/etc/httpd/users/* /private/etc/apache2/users/
So, I put my changes all back in and suddenly my local pages start working again, including my local Moveable Type installation. Yay me.

1 comments:

sheela said...

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Kaylee

http://www.craigslistpostingonline.info