Run Rails 3 Apps on Passenger

Update: Make sure you update Rubygems using sudo gem update –system.

Whilst I’ve been learning more about Rails 3, I’ve been using the built in rails server to run my code. Today I tried to run my Rails 3 app through Passenger on Apache, and immediately hit an error page:

uninitialized constant Rack::Runtime

It turns out that Passenger notices Rails’ new config.ru file, causing it to run as a Rack application. This requires a slight change in the app’s VirtualHost entry. The RailsEnv setting now becomes RackEnv:

# /etc/apache2/apache2.conf
# RailsEnv development
RackEnv development

But that wasn’t all. My development machine was still running Passenger 2.2.7, which wouldn’t support Rails 3. To ensure a clean slate, I removed the old versions of Passenger and installed the latest build (2.2.11 at the time of writing). Once installed, I ran the standard Passenger installation script and updated apache2.conf:

$ sudo gem update --system
$ sudo gem uninstall passenger
  # Remove all versions of Passenger
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
# /etc/apache2/apache2.conf
# Passenger mod_rails
# NOTE: Your paths may be different. Use the config generated by Passenger's install script)
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11
PassengerRuby /usr/bin/ruby1.8
 
RailsEnv development
RackEnv development

After a quick restart of Apache, Passenger kicked in and my new Rails 3 app was up and running!

References

Rails: Upgrade Passenger for Rails 2.3.3

I recently upgraded a project from Rails 2.3.2 to 2.3.3, after which I started getting strange the following error from Passenger:

undefined method 'rewind' for #<UNIXSocket:0xf6206c18>

After a little Googling, I discovered that I also needed to upgrade passenger from 2.1.2 to the current version 2.2.4. If you’re using RubyGems, this is a quick and easy:

gem update passenger
passenger-install-apache2-module

Once the Passenger installation has finished, be sure to update your apache config to point to the new version of Passenger:

# apache2.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4
PassengerRuby /usr/bin/ruby1.8