Ubuntu Hardy - mod_rails installation
Phusion's Passenger (mod_rails) is an exciting development in serving your Ruby on Rails application with the Apache web server.
Incredibly simple to install and use, you can have a rails application up and running in no time. You don't have to worry about ports or setting up a proxy to another server.
Prerequisites
To get the most out of this article you need to have a couple of things preinstalled:
Firstly, you need Apache installed (see this article).
Secondly, you need ruby and rubygems installed (if not please see the Ruby on Rails article).
mod_rails installation
Passenger (mod_rails) is a rubygem.
We need to update the rubygems install:
sudo gem update
and then install passenger:
sudo gem install passenger
Once completed, we need to install the Apache2 module:
sudo passenger-install-apache2-module
A dialogue opens in the terminal and starts with:

As suggested, press 'Enter/Return':

I deliberately left the Apache headers off the installation until this point as I want to demonstrate how easy the installation is.
The passenger (mod_rails) install has found a missing dependency - let's press 'Enter/Return':

How cool is that? It tells us what to do.
Well, let's go ahead and install the headers (we'll use aptitude though):
sudo aptitude install apache2-prefork-dev
Once done, we can try the install again:
sudo passenger-install-apache2-module
All being well, the install will complete with instructions at the end letting us know we need to add some lines to the main Apache2 config file.
No problem:
sudo nano /etc/apache2/apache2.conf
Note: Passenger is an active gem and is being updated all the time. Rather than copy and paste the output I show below, please ensure you copy and paste the output from the install itself.
At the time of writing the article (well, updating it actually) I installed passenger v1.0.4 - you may have installed a later version.
So, for my v1.0.4 install, I added the following lines to my apache2.conf:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-1.0.4/ext/apache2/mod_passenger.so
RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.4/bin/passenger-spawn-server
RailsRuby /usr/bin/ruby1.8
Apache restart
Now all we need to do is restart Apache:
sudo /etc/init.d/apache2 restart
Done
That's all we need to do to install mod_rails onto our Slice.
The next article will show how to create a Ruby on Rails application and serve it using passenger - an incredibly easy process.
PickledOnion

Subscribe to Feed
Article Comments:
Rex commented 15 days ago:
I just followed the instructions but passenger is now 1.0.4
LoadModule passengermodule /usr/lib/ruby/gems/1.8/gems/passenger-1.0.4/ext/apache2/modpassenger.so RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.4/bin/passenger-spawn-server
PickledOnion commented 15 days ago:
Hi Rex,
Thanks for the heads up - things change quickly around here!
I will likely update the article but you are right to point out that following the instructions shouldn't be done blindly - they are a guide and, as you found out, often out of date as soon as they are published.
PickledOnion
Lars Haugseth commented 9 days ago:
Can't get the passenger gem to install:
$ sudo gem update Updating installed gems Nothing to update $ sudo gem install passenger ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) Gem::RemoteFetcher::FetchError: bad response Not Found 404 reading http://gems.rubyforge.org/gems/passenger-1.0.5.gem
Hongli Lai commented 9 days ago:
Lars: please wait until tomorrow. RubyForge is still updating their mirrors.
Jay H commented 3 days ago:
I installed passenger successfully, but when I do: sudo passenger-install-apache2-module, it always come up with "sudo: passenger-install-apache2-module: command not found ". I'm going crazy, can you help me?
chris commented 3 days ago:
Note that build-essential is required
sudo apt-get install build-essential
PickledOnion commented 3 days ago:
Hi Chris,
As with your other comment, build-essential is a part of the basic Slice setup (please see the setup articles).
I also recommend using aptitude over apt-get (just as I use in all the Hardy articles) for various reasons.
Thanks,
PickledOnion