Functino

My daily struggle with webdevelopment

How to deploy a rails application – installing and using mod_rails aka passenger

Ruby on Rails is great and it is really fun to develop with it. But when it comes to deployment it’s hard for a beginner. I tried different approaches, cgi, fastcgi and mod_rails.
I really love mod_rails (also known as passenger), it’s easy to install and to deploy your application: you just need to upload it. Don’t worry about mongrel, webrick and a bunch of configuration tasks…

So I had a simple Debian server. I installed Ruby,  Rails and mod_rails on my server.

First I installed ruby and some other needed packages.

apt-get install ruby
apt-get install libyaml-ruby
apt-get install libzlib-ruby
apt-get install rdoc
apt-get install libopenssl-ruby1.8
apt-get install ruby1.8-dev
apt-get install libmysql-ruby
apt-get install irb
apt-get install sqlite3

To install rubygems I downloaded rubygems from http://rubyforge.org/frs/?group_id=126, unpacked it and run

ruby setup.rb

Because evrytime I tried a “gem install …” I got a “comman not found” I created the following symlink:

ln -s /usr/bin/gem1.8 /usr/bin/gem

Then I installed the sqlite3 gem and Rails:

gem install sqlite3
gem install rails

Installing passenger/mod_rails is easy – just install the gem and run the command “passenger-install-apache2-module” – it will tell you evrything you have to do. In my case the following steps were necessary:

apt-get install apache2-prefork-dev
gem install passenger
passenger-install-apache2-module

Now you have to enable mod_rails in your apache config. Just add this lines:
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/ruby1.8

Now upload your Application (via FTP for example) and change the document root in your apache config to the public-folder of your app.

Set up your database, edit database.yml, run your migrations and you’re done.

If you get a weird passenger error when you access your application try to change the owner of your environment.rb from root to www-data.

Once you get the hang of it, deploying is really easy!

Leave a Reply