Ubuntu Intrepid - 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:

mod_rails installation 1

As suggested, press 'Enter/Return':

mod_rails installation 2

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':

mod_rails installation 3

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 v2.0.6 — you may have installed a later version.

So, for my v2.0.6 install, I added the following lines to my apache2.conf:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6
   PassengerRuby /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.

Mike

Article Comments:

Tom commented Fri Feb 06 12:59:32 UTC 2009:

Worth noting that if you are having trouble with installing sqlite 1.2.4 against ruby enterprise (and gem in general) you need to install the sqlite dev package;

sudo aptitude install libsqlite3-dev

Mike commented Thu Feb 12 20:47:16 UTC 2009:

Having trouble with Passenger not recognizing Rake (it says * Rake... not found). Although when I do sudo gem list, it is there.. not sure what is going on there?

Mike commented Thu Feb 12 21:22:04 UTC 2009:

Figured it out - be careful of your $PATH and how you symlink. I highly recommend Deploying Rails Application by Ezra Z. Goes great hand in hand with these tutorials if you are new to deploying rails apps.

ahmad commented Wed Mar 04 03:12:03 UTC 2009:

getting the following error when running the command: sudo gem install passenger

Building native extensions. This could take a while... ERROR: Error installing passenger: ERROR: Failed to build gem native extension.

ahmad commented Wed Mar 04 03:14:17 UTC 2009:

/usr/bin/ruby1.8 extconf.rb install passenger extconf.rb:1:in require: no such file to load -- mkmf (LoadError) from extconf.rb:1

ahmad commented Wed Mar 04 03:15:29 UTC 2009:

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.1 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.1/ext/fastthread/gem_make.out

any ideas?

p.s sorry for the spam, but kept getting an error when posting comment

Eric Gruber commented Sat Mar 07 02:58:11 UTC 2009:

I'm also getting the same error message as ahmad:

Error: Error installing passenger ...

Eric commented Sun Mar 08 16:11:33 UTC 2009:

Here's a fix I found if gem install passenger doesn't work:

  1. Use the utility wget to download the source to your server:

wget http://rubyforge.org/frs/download.php/48622/passenger-2.0.6.tar.gz

  1. Once downloaded, unpack passenger by running this command:

tar xzvf passenger-2.0.6.tar.gz

  1. Run the installer:

./passenger-2.0.6/bin/passenger-install-apache2-module

  1. If you're missing any programs dependent for Passenger to run, the shell will let you know. I had to install three additional packages, but installation instructions were included on the screen for every package.

  2. You'll need to restart Apache when finished:

sudo apache2ctl -k restart

Additional documention on installing Passenger can be found at http://www.modrails.com/install.html

Lex Sheehan commented Thu May 07 20:12:12 UTC 2009:

If you get the following error message:

no such file to load -- mkmf (LoadError)

then run the following commands:

sudo apt-get install ruby1.8-dev sudo apt-get install build-essential

Now, you can finish your install:

sudo gem install passenger

Aaron Blohowiak commented Sat May 30 04:36:21 UTC 2009:

if none of the above work, try

sudo aptitude update

and then

sudo aptitude install ruby1.8-dev build-essential

finally

  sudo gem install passenger

and you should be done

Edgar O. Silva commented Wed Jul 01 04:43:16 UTC 2009:

Almost Everything seems to be installed correctly but when I try to run "sudo passenger-install-apache2-module" I receive the message "sudo: passenger-install-apache2-module: command not found",

Any Ideas Guys?

James commented Fri Jul 17 13:50:26 UTC 2009:

I had to do what Aaron suggested, then I got the same error as Edgar. Usually these tutorials are great :/

Andrew Short commented Fri Aug 14 11:35:21 UTC 2009:

If you're running into problems with the command not being found when using sudo (as you can't edit the PATH variable to add the rubygems bin) you can just use which passenger-install-apache2-module to get the full path, then use sudo /full/path/to/passenger-install-apache2-module

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)