how to install ruby on rails and lighttpd on ubuntu

Hey folks. It’s interesting how difficult it was for me to get Rails up and running on Lighttpd. I’ve tried lot’s and lot’s of tutorials, but none of them seemed fit to me. I came up with this solution, wich is actually a merge of lot’s tips. Feel free to contribute, and I hope that this helps you out.

1) First, include UNIVERSE on your sources.list. It is located on /etc/apt/sources.list. If you are unsure, take a look at this web-site. It may help you out. Remember to sudo, or be root to do everything

2) Then update your package list and upgrade your machine.

apt-get update
apt-get upgrade

3) Install the build-essential package. It has the most-used tools to compile programs from source.

apt-get install build-essential

4) Install ruby and everything it needs.

apt-get install ruby1.8 ruby1.8-dev irb1.8 rdoc1.8 libyaml-ruby libzlib-ruby libopenssl-ruby

5) Create simbolic links for ruby. The installation made before create binaries with unfriendly names (e.g. ruby1.8). So, we create links to be able to use “ruby” and “irb” from the console:

ln -s /usr/bin/ruby1.8 /usr/bin/ruby
ln -s /usr/bin/irb1.8 /usr/bin/irb

6) Download and install RubyGems

cd ~
mkdir ruby_install/ruby_gems
cd ruby_install/ruby_gems
tar xvzf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb

7) Install Rails with RubyGems

gem install rails --include-dependencies

PS: Sometimes, on machines behind network proxies, the above command will not work. On this case, you can manually install each of Rails components. They can be downloaded from and must be installed on this order:

  • Rake
  • ActiveSupport
  • ActiveRecord
  • ActionPack
  • ActionMailer
  • ActionWebService
  • Rails

8 ) Install RedCloth if you plan on using textilize.

gem install redcloth

9) Now, it’s time to install FastCGI

apt-get install libfcgi libfcgi-dev libfcgi-ruby1.8
gem install fcgi

10) Install MySQL client libraries (if you are using MySQL)

apt-get install libmysqlclient15-dev libmysql-ruby1.8
gem install mysql

PS: When gem install asks you whitch version of mysql to install, just choose the greater version number for your system.

11) Install lighttdp

apt-get install lighttpd

12) Save a backup copy of your /etc/lighttpd/lighttpd.conf

13) Use this lighttpd.conf. Remember to change var.railsdir
server.modules = ( “mod_rewrite”, “mod_accesslog”, “mod_fastcgi”, “mod_compress”, “mod_expire” ) = “/var/run/”

var.railsdir = “/home/web/test”

server.error-handler-404 = “/dispatch.fcgi”
server.document-root = var.railsdir + “/public/”

server.errorlog = var.railsdir + “/log/lighttpd.error.log”
accesslog.filename = var.railsdir + “/log/lighttpd.access.log”

url.rewrite = ( “^/$” => “index.html”, “^([^.]+)$” => “$1.html” )

compress.filetype = ( “text/plain”, “text/html”, “text/css”, “text/javascript” )
compress.cache-dir = var.railsdir + “/tmp/cache”

expire.url = ( “/favicon.ico” => “access 3 days”,
“/images/” => “access 3 days”,
“/stylesheets/” => “access 3 days”,
“/javascripts/” => “access 3 days” )

# Change *-procs to 2 if you need to use Upload Progress or other tasks that
# *need* to execute a second request while the first is still pending.
fastcgi.server = ( “.fcgi” => ( “localhost” => (
“min-procs” => 4,
“max-procs” => 4,
“socket” => var.railsdir + “/tmp/sockets/fcgi.socket”,
“bin-path” => var.railsdir + “/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
) ) )

mimetype.assign = (
“.css” => “text/css”,
“.gif” => “image/gif”,
“.htm” => “text/html”,
“.html” => “text/html”,
“.jpeg” => “image/jpeg”,
“.jpg” => “image/jpeg”,
“.js” => “text/javascript”,
“.png” => “image/png”,
“.swf” => “application/x-shockwave-flash”,
“.txt” => “text/plain”

# Making sure file uploads above 64k always work when using IE or Safari
# For more information, see
$HTTP[“useragent”] =~ “^(.*MSIE.*)|(.*AppleWebKit.*)$” {
server.max-keep-alive-requests = 0

14) Set adequate permissions on your application’s folders:

chmod -R 775 log/
chmod -R 775 public/
chmod -R 775 tmp/

15) You’re done.

There’s a small catch on this stuff: You won’t be able to /etc/init.d/services/lighttpd stop or restart. For some reason, lighttpd loose it’s connection with init.d, and you can only stop it sending TERM signals from the command line:

$ sudo ps -A | grep lighttpd
1234 lighttpd
$ sudo kill -9 1234

Using = “/var/run/” will take care of the job! Config example updated. Thanks, raul.
That’s it. I hope it helped you.


~ by Dante Regis on March 6, 2007.

4 Responses to “how to install ruby on rails and lighttpd on ubuntu”

  1. Thank you very much.

    In order to be able to restart the process I tried with = “/var/run/”

    in the conf file

  2. That’s right, raul! It’s incredible that you commented this, because I just figured it out yesterday, and your comment reminded me of updating the post! thanks

  3. Hi,

  4. Hi,
    I have followed all the steps given above but when i restart lighttpd & check the status it says “lighttpd is not running”. But when i remove mod_fastcgi from Lighttpd.conf file & restart lighttpd, it works. i have been trying to pinpoint the problem but to no avail…pls help

    Thanx in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: