CentOS - 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:
sudo yum install httpd-devel apr-devel apr-util-devel
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 Apache config file.
No problem:
sudo nano /etc/httpd/conf/httpd.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 I installed passenger v2.1.3 - you may have installed a later version.
So, for my v2.1.3 install, I added the following lines to my httpd.conf:
LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-2.1.3
PassengerRuby /usr/bin/ruby
Apache restart
Now all we need to do is restart Apache:
sudo /etc/init.d/httpd restart
Done
That's all we need to do to install mod_rails onto our Slice.
The next article will show us how to create a Ruby on Rails application and serve it using passenger - an incredibly easy process.


Article Comments:
Tom commented Wed May 12 04:34:07 UTC 2010:
If you get an extra passenger error warning about openssl make sure openssl and openssl-del are installed. If not install them: yum install openssl and yum install openssl-devel.
Then: cd ruby-1.8.4/ext/openssl ruby extconf.rb make make install
Then run the sudo passenger-install-apache2-module and everything should work!!
Tom commented Fri May 14 11:55:25 UTC 2010:
I have installed passenger and passed all the errors etc, however whatever I try, I can't get it to serve my rails application. I don't get any errors in my httpd logs and have tried allsorts of tests. Is there anything I could be missing?
Tom commented Fri May 14 14:04:33 UTC 2010:
Okay, sorted it! If there are any other people bemused. You have to make sure that the 3 lines of code for passenger in the httpd.conf file are right at the end and in my case replace lib64 with lib, ensuring you have the right passenger v. number in place. Hope this helps.
almozavr commented Sat Jul 10 18:12:27 UTC 2010:
Is there is a option to check if passenger module to apache works correctly?
Gent commented Fri Sep 02 18:43:25 UTC 2011:
When I put following into httpd.conf and restart httpd, i get syntax error message
LoadModule passengermodule /usr/local/rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.8/ext/apache2/modpassenger.so PassengerRoot /usr/local/rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.8 PassengerRuby /usr/local/rvm/wrappers/ruby-1.8.7-p352/ruby
ERROR MESSAGE IS Starting httpd: httpd: Syntax error on line 1001 of /etc/httpd/conf/httpd.conf: Cannot load /usr/local/rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.8/ext/apache2/modpassenger.so into server: /usr/local/rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.8/ext/apache2/modpassenger.so: wrong ELF class: ELFCLASS32
Jered commented Sat Sep 03 16:10:17 UTC 2011:
Gent, it sounds like the passenger module got compiled as a 32-bit module, but you're running it on a 64-bit server. It should have worked out the architecture for itself, but since it didn't, try running the following command before the installation procedure:
export ARCHFLAGS="-arch x86_64"
Hopefully that will make sure the module gets compiled properly.
Paul commented Fri Dec 30 01:12:50 UTC 2011:
i ran into the same problem as Gent, and banged my head on the keyboard way too long...until i found this, the correct answer. doh!
http://serverfault.com/questions/173773/how-to-compile-64-bit-apache-modules-on-centos
Jered commented Thu Jan 05 15:44:21 UTC 2012:
Thanks for posting the solution Paul, really appreciate it. In case the link should one day change, the basic answer is to remove "apr.i386" from the system.
Jigar Vyas commented Tue Jun 05 07:03:19 UTC 2012:
really really helpful post...