Setting local Ruby on Rails development environment with Lighttpd and FastCGI

Tired of typing ./script/server? Yeah, me too. Especially with Lighttpd / FastCGI configured for PHP at hand on my development machine - pure envy. So I gave a try with my Ruby on Rails applications.

Easy as pie - first add a custom domain to your /etc/hosts:

127.0.0.1	myapp.local

Then - add FastCGI handler to your lighttpd.conf

$HTTP["host"] =~ "myapp.local" {
	server.indexfiles          = ( "dispatch.fcgi" )
	server.document-root       = "/path/to/myapp/public/"
	server.error-handler-404   = "/dispatch.fcgi"
	fastcgi.server = (
		".fcgi" =>
			( "localhost" =>
				(
					"socket" => "/tmp/myapp.socket",
					"bin-path" => "/path/to/myapp/public/dispatch.fcgi",
					"bin-environment" => ( "RAILS_ENV" => "development" )
				)
			)
	)
}

Restart your Lighttpd and your done. Unless…

Unless you require some custom libs in your Ruby on Rails application. Then you should modify your code (I keep all my require statements in myapp/config/initializers/requires.rb) from:

require "lib/mylib.rb"

to:

require Rails.path.join("mylib.rb")

No more those nasty 500’s! This setup will also work for subdomains, ie. thisis.myapp.local (as long you as handle them /etc/hosts or anywhere else).