Deploying Rails Application on Apache with Phusion Passenger

facebookdc

This morning I put on my system admin hat at work once again. The challenge was to setup a Rails development environment on our production server at the cloud and then deploy a Rails application on Apache.

This article is not really a tutorial, although it’s posted under How-to category. It’s more like a log of my actions in carrying out this task; the problems I faced and what I did to get around them, so that I can trace them back if I ever partake a similar task in future.

Rails have several deployment options and Phusion Passenger a.k.a. Mod Rails is the principle of them. It supports both Apache and the lightweight Nginx Server. Check out there documentation page.

Here’s how it went

Logged into the remote server(CentOS 5.0) using ssh

Installed Rails

gem install -v=2.2.2 rails

Installed MySQL gem

gem install mysql — –with-mysql-include=/usr/include/mysql –with-mysql-lib=/usr/lib/mysql/

Installed Phusion Passenger

gem install passenger


Warning received. Required Software missing

Apache 2 development headers… not found

Installed Apache 2 Development Headers

yum install httpd-devel

Installed Apache module for Passenger

passenger-install-apache2-module

Configured Apache 2 to load the mod_passenger module by adding these lines in /etc/httpd/conf/httpd.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/ruby

Uploaded a sample Rails App(myrailsapp) to /home

Added following lines in /etc/httpd/conf/httpd.conf to create a new virtual host

<VirtualHost *:80>
ServerName rails.myserver.com
DocumentRoot /home/myrailsapp/public
RailsEnv    development
</VirtualHost>

Restart Apache

service httpd restart

Went to http://rails.myserver.com.

Standard Error page for Phusion Passenger displayed. Instructed to consult Apache error log

Checked out the Apache Error Log

cat /etc/httpd/logs/error_log

The last error was

Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update –system` and try again.

Updated RubyGems

gem install rubygems-update
update_rubygems

Restarted Apache and went to http://rails.myserver.com again. The following error was showing on the page

no such file to load — sqlite3

Reason: SQLite3-Ruby Gem missing. Tried to install it

gem install sqlite3-ruby

Failed. The system doesn’t have SQLite3 installed

checking for sqlite3.h… no

Installed SQLite3 by building in from source

wget http://www.sqlite.org/sqlite-amalgamation-3.6.17.tar.gz
tar xvzf sqlite-amalgamation-3.6.17.tar.gz
cd sqlite-3.6.17
./configure
make
make install

Installed SQLite3-Ruby Gem

gem install sqlite3-ruby

Restarted Apache and visited http://rails.myserver.com

SUCCESS!

Advertisements

4 thoughts on “Deploying Rails Application on Apache with Phusion Passenger

  1. I’m using sqlite with rails and the passenger module. I’m having problems with mod_passenger when I’m trying to update. With mongrel and webrick the app runs without problems.
    On your development website are also updating your sqlite db?

    regards
    — Andi

  2. @Andi – the only reason I had to install sqlite is because it was required by Rails, even when I’m not using it. However, passenger didn’t complain. May be you should try locating the exact problem with whatever error message you are getting.

  3. hi!..am a newbie!…am getting starting on apache!..rails!
    i have followed everything from here!…

    am using virtualbox in ubuntu…

    guest-10.04 server
    host-10.04 desktop

    but the problem is that am unable to fine the application by name!..but it came with the ip and port number.

    for virtual host it not at all woring!…can u tell me how to do this things!…

  4. Pingback: Blog stats 2010 « Glorified Geek

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s