Phusion Passenger + Apache2 for RoR

Ok here goes my little notes on making a small nifty Rails App run on Apache2 with mod_rails provided by Phusion Passenger.

The installation of mod_rails is pretty straight forward. The installation steps are small and well documented here plus you have the amazing rails cast by Ryan Bates.

After watching the videos and reading the steps well I thought its gonna be a breeze I am going to wind up in 15mts and going to enjoy the night! Sigh! But things went wrong a 15mts exercise consumed close 4/5hrs of my time.

Ok here is where the fun is all about – I use RVM to maintain my installs. The first step in passenger installation is obviously to install the passenger gem. Now I felt it would be good to put the passenger in global gemset rather than any specific one and there by making it available to all. So I did

rvm use 1.9.2@global

Then
gem install passenger

Then
passenger-install-apache2-module

In my system after the above step it said some libraries were missing in the system (Ubunut Lucid Lynx), so I had to correct those by manually installing them with apt-get. After I got all the dependencies installed I again ran the passenger install and everything went fine.

At the end of the passenger-install step, it would spew a few lines of code which we need to put it on apache2.conf file. For me those lines looked like

LoadModule passenger_module /home/arun/.rvm/gems/ruby-1.9.2-p136@global/gems/passenger-3.0.5/ext/apache2/mod_passenger.so
PassengerRoot /home/arun/.rvm/gems/ruby-1.9.2-p136@global/gems/passenger-3.0.5
PassengerRuby /home/arun/.rvm/wrappers/ruby-1.9.2-p136@global/ruby

Now I added a Virtual Host to Apache to point to my sample Rails App by adding the following to the apache2.conf


<VirtualHost *:80>
ServerName http://www.depot.com
DocumentRoot /media/harddisk/work/ror/depot/public
<Directory /media/harddisk/work/ror/depot/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

So that is it – restart the apache and hit http://www.depot.com in your browser you should see your rails app. But hey! wait won’t entering depot.com make the browser go and search the Internet rather than your local system. Well yes, so we have to make a small exception in the file /etc/hosts. In the file add a line

127.0.0.1 http://www.depot.com
127.0.0.1 depot.com

Ok all set! now again enter the URL to your browser biff! now got a new error

no such file to load -- bundler

The error was obvious it was not able to find the bundler. But from terminal I gave

gem list -d bundler

It was showing proper output, means bundler gem was there up and kicking. Mind you this command I was giving from the gemset which I was working on. Then I started googling this error and got many suggestions and tried one by one and spent nearly 3hrs and couldn’t make any break through. It was really frustrating.

Then finally help arrived from Hongli Lai of Phusion Team through the Phusion Passenger Google Group. She was pointing to me that ruby I am using for Phusion given in apache2.conf file was pointing to global gemset while bundler was installed in the other gemset. So I had replace the line in apache2.conf to pick up the ruby from the gemset which I was working on. So suppose foo is your gemset change PassengerRuby line in apache2.conf to

PassengerRuby /home/arun/.rvm/wrappers/ruby-1.9.2-p136@foo/ruby

Yes! This worked. Now if you are running a static site things would start working now. But my sample app had some tables so when I fired up app in browser it was complaining that tables were missing in the production.

So if you run into a similar situation just migrate the tables to production with rake.
rake db:migrate RAILS_ENV="production"

In my case I had some load scripts as well which was for loading some sample data to tables, for loading those data into production use the rails runner with following option

rails runner -e production script/load_xxxxx.rb

That is it, now I see my rails app working well in my Apache2 server with mod rails.

Ok! here is a small tip, in order to restart the Rails App after changes you need not restart the server, you can give this command from Rails Application Root

touch tmp/restart.txt

Passenger would see the timestamp of restart.txt and reload the Rails App if needed.

Advertisements

2 thoughts on “Phusion Passenger + Apache2 for RoR

  1. Pingback: How to install apache2 and php 5 on windows 2003 | PHP5 Web Hosting

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