Suffix

Published by Simon Schoeters

Missing gems in LightTPD

After upgrading Ruby to 1.8.6 and Rails to 2.0.2 I ran intro problems with my installed gems. My application couldn't find any of the installed gems anymore! The gem list command returned the installed gems like you would expect and even the ./script/console environment in my Rails application found the gems I needed but requiring a gem in one of my controllers like:

require 'somegem'

returned the following error:

MissingSourceFile (no such file to load -- somegem)

It took ages to find out what the problem was. My GEM_PATH variable - this is where RubyGems looks for the installed gems - was set. I could find the gem from everywhere, except from within the controllers in my application. However, it did work fine when I ran the WEBrick server but when using my LightTPD production server everything went fubar.

Turned out I forgot to tell LightTPD to use the new GEM_PATH, other than the default one. You can do this in the LightTPD configuration file. Maybe I changed the gem installation directory as I build RubyGems from source without knowing? Add the following to your LightTPD configuration file (change the paths where needed) and reload the server.

fastcgi.server =
(
 ".fcgi" =>
 (
  "localhost" =>
  (
   "min-procs"       => 1,
   "max-procs"       => 1,
   "socket"          => "<app>/tmp/sockets/fcgi.socket",
   "bin-path"        => "<app>/public/dispatch.fcgi",
   "bin-environment" =>
   (
    "RAILS_ENV" => "production",
    "GEM_PATH"  => "/usr/local/lib/ruby/gems/1.8/"
   )
  )
 )
)

That's it, Suffix is now happily running the latest Ruby on Rails version.