Tuesday, July 15, 2008

Install Phusion Passenger on Cent OS 5

Phusion Passenger (mod_rails/mod_rack) is an apache module that makes deployment of Ruby/Rails applications as simple as PHP applications. It does not require use of any ruby specific tools to deploy application. All you have to do is copy your source files in appropriate directories on server and your code changes will be deployed. Main advantage of passenger is it allows to deploy rails application reliably on shared hosting environment. Passenger is not available for windows. 

Lets see how to install Passenger on Cent OS. Cent OS 5.1 comes with Apache 2.2.3 installed. First of all make sure Ruby, Gems, Rails and ruby development headers is installed on the system, Issue following commands as root: 

yum install ruby
yum install irb
yum install rdoc
yum install ruby-devel
yum install rubygems
Now install rails gems:

gem install rails -y

Also install Apache development header files.

yum install httpd-devel
Now we have all prerequisites covered. Lets proceed with installation of Passenger gem.

gem install passenger
After installing passenger and its dependencies make sure that Apache is stopped, launch passenger installer for Apache module from command line.


The command line based installer is pretty good it will check all dependencies and inform you if any dependency is missing. After the module is installed. create a rails application in /var/www/htdocs folder.

rails demo
Now open httpd.conf file in /etc/httpd/conf folder. Add following lines in this file.

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.1/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.1
PassengerRuby /usr/bin/ruby

These paths could be different for your system. Now lets configure virtual host for rails application at bottom of httpd.conf. Add these lines at bottom of file:

<VirtualHost *:80>
      ServerName www.demo.com
      DocumentRoot /var/www/html/myapp/public
Make sure DocumentRoot points to public directory of your rails application. Also add server name alias to hosts file in /etc/ folder. Now start apache server from console.

service httpd start
Your new rails application should be running now with Phusion Passenger.