Rails Sucks, Long Live Rails

Wowsers. I just spent two nail-biting, hair-pulling days getting Ruby on Rails running on a new dedicated server. What’s the deal here? I spent the first six hours trying to get Capistrano to work with darcs. Then I gave up on Capistrano.

I didn’t know anything about Mongrel, nginx, Lighttpd, or any of that stuff, so I decided to try the simplest setup I could think of: Apache2 with FastCGI. I’d done this on a shared host before, so at least I had some vague idea of what to expect. Some things I learned:

  • Do not use Ubuntu’s rubygems package; build from source. The Ubuntu package has a weird configuration that stores gems under /var, where nothing can find them.
  • Do not use Ubuntu’s fcgi-ruby package. Install the gem (see below).
  • Make sure your web-data user (or whatever user Apache runs as) has write privileges on RAILS_ROOT/log, RAILS_ROOT/tmp, RAILS_ROOT/index (if you’re using Ferret), and RAILS_ROOT/public (if you’re using page caching).
  • Make sure there are no leftover files owned by other users in any of those aforementioned directories.
  • Don’t rely on Apache to provide Rails with environment variables like RAILS_ENV and PATH. Set them in environment.rb.

My conclusion, after I finally got the app running: Rails has major work to do when it comes to startup error reporting. When dispatch.fcgi dies repeatedly without neither output nor log messages, there’s something wrong. Seriously, how hard could it be to dump a plain-text HTTP response with a stack trace? That way I’d at least know why it won’t start, instead of staring at “Rails application failed to start properly” for hours on end.

For the record, here was the installation recipe I came up with. This is on Ubuntu Feisty:

sudo aptitude install mysql-server mysql-client

sudo aptitude install memcached

Basic ruby essentials:
sudo aptitude install ruby libruby1.8-extras irb rdoc ri

Extra ruby libraries:
sudo aptitude install libreadline-ruby libopenssl-ruby libmysql-ruby

Essentials for building native ruby extensions:
sudo aptitude install build-essential ruby1.8-dev libfcgi-dev

The latest version of rubygems (NOT the Ubuntu package):

wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
tar -xzf rubygems-0.9.4.tgz
cd rubygems-0.9.4
sudo ruby setup.rb

sudo gem install --include-dependencies --no-rdoc --no-ri rake rails acts_as_ferret acts_as_taggable asciify BlueCloth builder cached_model chronic feedtools ferret hpricot memcache-client mongrel RedCloth fcgi