Monday, January 18, 2010

Passenger and Apache Load Order

On OS X (Snow Leopard), I'm trying to use Apache and Passenger to serve my Rails app. I ran into an issue where it just wouldn't load. Instead, I got errors saying that the server simply wasn't started (and Apache wasn't running).

Trick 1: What the Passenger PrefPane does

The first trick to getting it working was understanding exactly what the Passenger pref pane really does. When you add a Rails app to the Passenger pref pane, it:

Adds this to the bottom of httpd.conf

NameVirtualHost *:80

ServerName _default_

Include /private/etc/apache2/passenger_pane_vhosts/*.conf

Creates a vhost file named with the address you specified in the pref pane

Puts the following in the vhost file

ServerNamecsh.local

DocumentRoot "/Users/cpowell/projects/csh/public"

RailsEnv development

Order allow,deny

Allow from all

Trick 2: Load Order

When you set up Passenger, if you followed instructions, you made a file called other/passenger.conf. Your passenger.conf looks something like this:

Include /private/etc/apache2/extra/httpd-vhosts.conf (this loads your vhosts, if you're putting them in the file named, logically, httpd-vhosts.conf. This is where I put things when I wasn't using the Passenger pref pane. Note that this is commented out by default, so if you're going to put your things there, you need to uncomment it.)

Include /private/etc/apache2/passenger_pane_vhosts/*.conf (this is where the Passenger pref pane puts your apps)

Trick 3: Passenger Pref Pane appends

After you've set up your application in the Passenger pref pane, if you modify it, the behavior is slightly odd. For example, I might switch the app from running in Development to Production. When I do this, the pref pane adds the following text to the vhost configuration in passenger_pane_vhosts/[my app].conf:

Order allow,deny

Allow from all

It doesn't replace the original entry; it adds a new entry. This means I get several directory entries over time. So I have to go back and clean up the vhosts file by hand.

None of these things are killer, but I at least found myself rather frustrated by them. Hopefully this saves someone else some time!

Eloy, I went to reproduce this and trick #3 didn't occur for me. I'll keep poking and log a bug if I can get it to happen again. Thanks for the followup, though, and thanks for the useful piece of software!