Tuesday, 2 May 2006

Tips from my rails installation

« Thinking of Ruby on Rails again | Main | eclipse 3.2 »

After my useless lucubration and following emendation, it's time to write something that may be helpful. Unfortunately, first I've to introduce the subject and hence I need to lucubrate a little more.

I developed my Ruby on Rails project on stakhanov (system configuration) and deployed it on stratagemma (system configuration). Debian and Ubuntu have a nice packaging tool that makes absolutely undifficult installing rails. Nonetheless I chose to get it using RubyGems because it's as easy and, in this way, I have more control:

  • I can maintain the development and production environments as much similar as possible and that could avoids unexpected and annoying problems. In my case, luckily, I could have installed the same Rails version (1.0.0) both on stakhanov and stratagemma but who assures me that this will be always valid?
    The same reasoning can be repeated for the development team: it is preferable to have an environment as uniform as possible and so one ignores the various exotic packaging system and goes directly to the source.
  • I can upgrade Rails without waiting that the distribution provide an apposite package. Considering the recent release of the 1.1 version of rails (while Debian etch and Ubuntu breeze are stuck at 1.0), that's not so unlikely.

Anyway apt is still fine and convenient and I used it to install on stratagemma ruby1.8, the DBMS, apache2 and every other necessary tool. The problem is how to integrate all these packages with what comes from RubyGems, particularly when, for avoiding incidental conflict with distribution's packages, you chose to install it and its gems outside the standard system directories. In this way various executable and library can't be found without setting specific environment variables:

# ruby
export RUBY_HOME=/path/ruby 
export RUBYLIB=$RUBY_HOME/local/lib/site_ruby/1.8

# ruby gem
export GEM_HOME="$RUBY_HOME/rubygems"
export RUBYOPT=RubyGems 

export PATH=$RUBY_HOME/bin:$GEM_HOME/bin/:$PATH

This solves the problem from command line but, to make work your rails application, you have to pass the same values to the web server. For apache2:

<VirtualHost your.domain.name>
  DocumentRoot /path/to/the/public/directory/in/the/rails/app

  SetEnv RUBY_HOME /path/ruby
  SetEnv RUBYLIB /path/ruby/local/lib/site_ruby/1.8
  SetEnv GEM_HOME /path/ruby/rubygems
  SetEnv RUBYOPT rubygems

That's fine for the CGI dispatcher but doesn't suffice for the FastCGI one and you have to add apposite directives. For libapache2-mod-fcgid (Ubuntu package for mod_fcgid):

  DefaultInitEnv RUBY_HOME /path/ruby
  DefaultInitEnv RUBYLIB /path/ruby/local/lib/site_ruby/1.8
  DefaultInitEnv GEM_HOME /path/ruby/rubygems
  DefaultInitEnv RUBYOPT rubygems

These are my tips :-) . In the web there are numerous tutorials with detailed description of each step to install rails, for a configuration similar to the mine, see for example Ruby, Rails, Apache2, and Ubuntu Breezy (5.10) on fo64.com.

Posted by Nicola Piccinini at 11:42 PM CEST in devel/