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:

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

Article Comments:

Rex commented Fri May 02 06:40:23 UTC 2008:

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 Fri May 02 09:23:46 UTC 2008:

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 Wed May 07 20:23:54 UTC 2008:

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 Wed May 07 23:36:04 UTC 2008:

Lars: please wait until tomorrow. RubyForge is still updating their mirrors.

Jay H commented Tue May 13 15:06:44 UTC 2008:

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 Wed May 14 01:42:22 UTC 2008:

Note that build-essential is required

sudo apt-get install build-essential

PickledOnion commented Wed May 14 09:12:05 UTC 2008:

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

Jari Jokinen commented Mon May 19 14:54:35 UTC 2008:

Jay H: I guess you don't have the gems bin directory in your path, so you have to use the full path:

/var/lib/gems/1.8/bin/passenger-install-apache2-module

Carl commented Mon Jun 02 05:47:58 UTC 2008:

I'm getting an error trying to build the native extension:

homeslice ~: sudo gem install passenger Bulk updating Gem source index for: http://gems.rubyforge.org/ Building native extensions. This could take a while... ERROR: Error installing passenger: invalid gem format for /usr/lib/ruby/gems/1.8/cache/passenger-1.0.5.gem homeslice ~: sudo passenger-install-apache2-module sudo: passenger-install-apache2-module: command not found homeslice ~: /var/lib/gems/1.8/bin/passenger-install-apache2-module -bash: /var/lib/gems/1.8/bin/passenger-install-apache2-module: No such file or directory

Any suggestions?

Carl commented Mon Jun 02 15:43:31 UTC 2008:

I was able to install it from source without any problems. Maybe the new gem doesn't like rubygems 1.1.0 perhaps?

Tony commented Tue Jun 03 23:22:50 UTC 2008:

I got the same error as Carl regarding the invalid gem format

Jeremy Pinnix commented Sat Jun 07 02:12:06 UTC 2008:

I also received the invalid gem format error. I went into the rubygems cache and deleted it, then tried again and was successful. Look for /usr/lib/ruby/gems/1.8/cache/passenger-1.0.5.gem and delete that.

Andy commented Tue Jun 17 17:23:47 UTC 2008:

After running

sudo aptitude install apache2-prefork-dev

I get:

Err http://archive.ubuntu.com hardy-updates/main libldap2-dev 2.4.7-6ubuntu4.1 404 Not Found [IP: 91.189.88.31 80] E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/o/openldap2.3/libldap2-dev2.4.7-6ubuntu4.1amd64.deb: 404 Not Found [IP: 91.189.88.31 80]

From looking on the server, I can see that there is a libldap2-dev2.4.7-6ubuntu4.2amd64.deb but not a libldap2-dev2.4.7-6ubuntu4.1amd64.deb

Is there any easy fix for this?

Andy commented Tue Jun 17 18:33:11 UTC 2008:

In reply to myself, running apt-get update has fixed the issue.

Nikolay Kolev commented Fri Jun 20 20:04:07 UTC 2008:

Isn't it better (cleaner, modular, etc) instead of modifying apache2.conf or httpd.conf to create a mod_passenger.conf under /etc/apache2/conf.d?

Also, passenger 1.0.5 said that it's recommended to install apache2-mpm-prefork.

Hunter commented Thu Jun 26 23:09:42 UTC 2008:

After restarting, I received this message:

"WARNING: The 'RailsSpawnServer' option is obsolete. Please specify 'PassengerRoot' instead. The correct value was given to you by 'passenger-install-apache2-module'.WARNING: The 'RailsSpawnServer' option is obsolete. Please specify 'PassengerRoot' instead. The correct value was given to you by 'passenger-install-apache2-module'. ...done."

Anything i should worry about?

prism commented Thu Jul 03 16:16:46 UTC 2008:

Even though all the software requirements are met, I get a problem probably caused by a conflict with apr.

"/usr/include/apache2/aprfileinfo.h:200: error: 'aprinot' does not name a type"

which terminates the passenger installation.

Anyone else had this happen?

Raymond Brigleb commented Fri Aug 15 20:28:46 UTC 2008:

Very, very helpful article. However, Passenger is a bit weird, and I'm trying to figure out how you would get Capistrano to offer the functionality of something like "deploy:web:disable," to take down your site for a bit, in an emergency. Any suggestions?

Chris commented Sun Aug 24 20:42:55 UTC 2008:

Have we figured out a workaround for us 256 slice users who experience Gem hanging at updating the source index?

PickledOnion commented Mon Aug 25 09:25:36 UTC 2008:

Hi Chris,

The main ruby and rubygems articles were updated several weeks ago with details of how to install rubygems v1.2 or above.

You can't upgrade. Uninstall the version you have and follow the articles for installing the newer version.

PickledOnion

dylan commented Thu Aug 28 05:01:56 UTC 2008:

Has an error about "sudo gem install passenger":

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

/usr/bin/ruby1.8 extconf.rb install passenger creating Makefile

make sh: make: not found

Anyone else had this happen?

PickledOnion commented Thu Aug 28 08:44:24 UTC 2008:

Hi dylan,

You need the build-essentials package installed (as shown in the Slice setup articles).

PickledOnion

Bryan commented Tue Sep 30 02:41:38 UTC 2008:

Could/should you skip the installation of rails in the Ruby on Rails article if you intend to install mod_rails? Is there an advantage or disadvantage to having both installed?

PickledOnion commented Tue Sep 30 09:26:32 UTC 2008:

Bryan,

You will still need to install rails as I assume you want mod_rails to serve your rails application?

I suspect you have confused the two - rails is the framework for the rails application. Mod_rails is the method of serving the rails application.

PickledOnion

Bryan commented Sun Oct 12 18:32:00 UTC 2008:

I have seen some articles suggest creating a passenger.conf to store the mod rails configuration information.

Would you recommend doing that? If so, how do you modify apache.conf to reference the new file?

Thanks,

Bryan

ralph commented Fri Oct 17 20:53:38 UTC 2008:

Hi,

When I install phusion on a webserver, after reloading apache2 , it tells me, that the apache can not bind to port 80, because it´s allready in use and that it´s not allowed to mix name-based and virtual-host. But ev´rything seems to be working allright. What does it mean?

regard

Ralph

Andrea commented Sun Nov 02 19:29:29 UTC 2008:

If i use passenger-memory-stats as a normal user, everything work fine. But if i use this command as root (as passenger advice) i get this error:

root@andrea-desktop:/home/andrea# passenger-memory-stats /usr/local/lib/site_ruby/1.8/rubygems.rb:636:in report_activate_error': Could not find RubyGem fastthread (>= 1.0.1) (Gem::LoadError) from /usr/local/lib/site_ruby/1.8/rubygems.rb:141:inactivate' from /usr/local/lib/site_ruby/1.8/rubygems.rb:165:in activate' from /usr/local/lib/site_ruby/1.8/rubygems.rb:164:ineach' from /usr/local/lib/site_ruby/1.8/rubygems.rb:164:in activate' from /usr/local/lib/site_ruby/1.8/rubygems.rb:49:ingem' from /usr/bin/passenger-memory-stats:18

what is it?

9sus commented Thu Nov 20 10:16:29 UTC 2008:

Anyone who has problems installing the gem, try this http://blog.realdimensions.com/2007/04/05/pesky-mkmf-load-error-in-ruby-on-ubuntu/

Per-Olof Hermansson commented Fri Dec 26 16:53:44 UTC 2008:

Hi I have installed Apache, RoR, MySQL, PHP according to you instructions, and everything has gone fine.

Now I have installed Phusion Passenger and when I try to start Apache again I get the following error:

Restarting web server apache2 apache2: Syntax error on line 194 of /etc/apache2/apache2.conf: Cannot load /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apa$ into server: /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apa$: cannot open shared object file: No such file or directory

How do I solve this?

Thanks for help,

Per-Olof

Ben Goulding-Huckle commented Sat Jan 03 08:32:42 UTC 2009:

Hi there, for me i can't get the install to start.

Tried it with both gems 1.2.0 found in this tutorial and the newest 1.3.1.

Any ideas? Thanks Ben

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

/usr/bin/ruby1.8 extconf.rb install passenger creating Makefile

make sh: make: not found

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

Zeba commented Thu Jan 08 05:58:55 UTC 2009:

Hey.. I've been trying to deploy my RoR application on ubuntu using passenger,REE,apache.... I've successfully installed all of them. I have my apache running and can see the welcome index page... But when I give my controller's name , I get 404 error... When I checked my error log, it says that ApplicationPoolServerExecutable is missing... And yes..that executable is nowhere on my system..!!!!! In fact I have a ApplicationPoolServerExecutable.cpp file..!!!!! I wonder after successful installations why didn't that executable get created???? If anyone figures out where have I gone wrong...PLEASE HELP.... Thanks in advance

Viktor Nordling commented Tue Feb 10 16:05:55 UTC 2009:

PickledOnion,

First of all, thanks for all your great articles!

Second of all, I am in dire need of help! My web site has become quite popular and it seems like passenger starts to behave quite badly under load.

After apached has been started, I normally have around 13-14 processes if I do "ps ax | grep apache | wc -l". After some time of load, the server becomes unresponsive and if I log in and count the processes again, they are usually around 130.

If I stop apache, the processes are still there. I have to manually kill -9 them.

I have updated to the latest version of passenger and I changed the spawn strategt from "smart" to "conservative". The server did stay for a few days after the upgrade, but now it's dying within 24 hours again.. :(

I am running a 256M slice and I have around 1000-2000 visitors per day, I have a feeling the server should handle it, if it just didn't go hay wire with spawning processes.

Any help would be greatly apreciated!

chovy commented Wed Apr 01 14:35:03 UTC 2009:

If you get a 403 error (forbidden), add these lines to your vhost:

<directory> Order allow,deny Allow from all </directory>

Jenny commented Wed May 27 21:26:48 UTC 2009:

If you have the following errors:

sh: make not found --or--- make: cc: Command not found

Please run the following commands:

. sudo aptitude install make

. sudo aptitude install gcc

Hope these help other people having problem!!

Simao commented Wed Oct 28 16:51:06 UTC 2009:

Hello,

congratulations for the different articles.

I was now following this article and got a strange error when doing the "sudo passenger-install-apache2-module" command. I get the following:

"gemprelude.rb:111: in 'pushgemversiononloadpath':undefined method '<=>' for nil:NilClass (NoMethodError) from gem_prelude.rb:11:in 'gem' from /usr/bin/passenger-install-apache2-module:18:in '<main>'"

Maybe I have skipped something? Hope you can help me! Thank you!

Simao commented Wed Oct 28 16:55:15 UTC 2009:

I forgot to add that I'm using Ruby 1.9.

Simao commented Wed Oct 28 17:31:04 UTC 2009:

Hi again=) nevermind my question, I changed back to ruby 1.8 and now it's working. MY app is with ruby 1.8, so it's OK like this. =)

Jason Green commented Mon Nov 23 16:07:19 UTC 2009:

As per a previous post above I was getting

./passenger-install-apache2-module: command not found

on a ubuntu slice using REE.

a quick locate shows the gem is installed here: /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.7/bin

so I run:

cd /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.7/bin; ./passenger-install-apache2-module

and it works :)

mattpaul commented Wed Sep 29 02:22:34 UTC 2010:

Been having trouble getting passenger to run my rails app and just found the fix. If your rails app contains the file config.ru, passenger will treat it as a rack app and IGNORE the RailsEnv you may have set from apache conf files. You can also set RackEnv (which is then detected) or (re)move the offending file. Enjoy!

timsegraves commented Sun Nov 07 06:48:38 UTC 2010:

I've been following all of the capistrano guides and everything has been very smooth installing Rails 3, Ruby 1.9.1, and MySQL until I got stuck at this error trying to the passenger apache module. Any ideas on this? The poster above just downgraded ruby to 1.8 and the error went away but I need 1.9 since I'm using Rails 3. Thanks.

$ sudo passenger-install-apache2-module <internal:gem_prelude>:114:in push_gem_version_on_load_path': undefined method<=>' for nil:NilClass (NoMethodError) from <internal:gem_prelude>:8:in gem' from /usr/bin/passenger-install-apache2-module:18:in<main>'

Andre Ortiz commented Fri Dec 31 06:28:49 UTC 2010:

After following this walkthrough, I ran into this error upon running this command:

Command: sudo /etc/init.d/apache2 restart

Error Message: /usr/sbin/apache2: symbol lookup error: /usr/sbin/apache2: undefined symbol: aprldapssl_init ...fail!

I added the lines to my apache2.conf file like so:

Located at the top of the apache2.conf file: LoadModule passengermodule /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/modpassenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2 PassengerRuby /usr/bin/ruby1.8

#

Based upon the NCSA server configuration files originally by Rob McCool.

#

Any ideas why this is failing? Thanks!

Bala Paranj commented Sat Oct 01 01:43:10 UTC 2011:

I am getting: Module "passenger" is not installed, ignoring.

I have Phusion passenger installed. Any ideas on how to fix it?

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)