Cherokee Web Server: Ruby on Rails with SCGI

Ruby on Rails with SCGI

Contents

Installation

You will need to install Ruby, and RubyGems. Most of the distributions provide packages for them, but in case your operating systems doesn't provide it here are the links to the web sites:


Ruby Gems

Now, we need to fetch the package list:

# gem update      
Upgrading installed gems...
Gems: [] updated

Ruby on Rails

Now, everything is ready to install Ruby on rails:

# gem install rails
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
Updating Gem source index for: http://gems.rubyforge.org
Install required dependency rake? [Yn]  
Install required dependency activesupport? [Yn]  
Install required dependency activerecord? [Yn]  
Install required dependency actionpack? [Yn]  
Install required dependency actionmailer? [Yn]  
Install required dependency actionwebservice? [Yn]  
Successfully installed rails-1.0.0
Successfully installed rake-0.7.0
Successfully installed activesupport-1.2.5
Successfully installed activerecord-1.13.2
Successfully installed actionpack-1.11.2
Successfully installed actionmailer-1.1.5
Successfully installed actionwebservice-1.0.0
Installing RDoc documentation for rake-0.7.0...
Installing RDoc documentation for activesupport-1.2.5...
Installing RDoc documentation for activerecord-1.13.2...
Installing RDoc documentation for actionpack-1.11.2...
Installing RDoc documentation for actionmailer-1.1.5...
Installing RDoc documentation for actionwebservice-1.0.0...

SCGI for Ruby on Rails

Now, it is necesary to install the SCGI interface of Ruby On Rails. In this case, we will need to download the "gem" file, and compile it:

# wget http://www.zedshaw.com/downloads/scgi_rails/scgi_rails-0.4.3.gem 
# gem install scgi_rails-0.4.3.gem

If this step fails, probably is because you need to install the Ruby development package first.

Example project

Lets create an example project. The following example uses /var/www to place the rails directory, but it doesn't matter what directory you use.

# mkdir /var/www/rails
# cd /var/www/rails
$ $ rails example
      create  
      create  app/controllers
[..]
      create  log/development.log
      create  log/test.log
And now, lets create a new control:
ruby script/generate controller MyTest
. This done, we can add a few lines to build a "Hello World" example. Edit app/controllers/my_test_controller.rb in order to make it look like this:
class MyTestController < ApplicationController
   def index
      render_text "Hello World"
   end
end

Start the SCGI server

$ cd example
$ scgi_ctrl config
What password do you want?

$ scgi_ctrl start

Cherokee configuration file

This is a configuration file of one of the approached you can use to run Ruby on Rails in Cherokee:


Documentroot /var/www/rails/example/
DirectoryIndex index.html

Directory /public {
  Handler file
}

Directory / {
  Handler scgi {
    Server localhost:9999
    ErrorHandler on
  }
}

Request "^/$" {
  Handler redir { Rewrite "" "/public/index.html" }
}

Test

Finally, the test:
http://localhost/MyTest