Using Passenger on OS X for Rails development

Manfred Stienstra

Lately a few things have been bugging me about Rails development using script/server. First, I can’t test through SSL and for applications who switch between SSL and non-SSL you really want your development environment too look as much like production as possible. And secondly, I have to manually manage my app server with script/server. This is a bit of a pain because some of our applications use ActiveResource to communicate so I need to start several app processes.

Proxying trough Apache solved the SSL problem, but now I had to remember on which ports I had to start my app server.

The solution turned out to be Passenger. First we install the passenger gem and compile mod_passenger.so.

$ gem install passenger
$ passenger-install-apache2-module

After that we turn on Apache at System PreferencesSharingWeb Sharing and edit the webserver configuration. I added everything to /etc/apache2/users/manfred.conf but Apache doesn’t really care where you put it, just remember to load mod_passenger.so before using Passenger specific configuration options.

Set up the Passenger configuration as explained at the end of the install script.

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Make sure our apps run in development mode.

RailsEnv development

Allow Apache serve files from our development directories.

<Directory "/Users/manfred/Code">
    Order allow,deny
    Allow from all
</Directory>

Finally, configure virtual hosts for our various projects.

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "/Users/manfred/Code/project1/public"
ServerName project1.local
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/manfred/Code/project2/public"
ServerName project2.local
</VirtualHost>

You’re reading an archived weblog post that was originally published on our website.