::You must have ninja focus to complete your mission::NinjaFocus::

Ruby on Rails




Ruby on Rails is a web application framework written in the Ruby programming language.

Rails can be installed from source but it is far easier to use the Ruby Gems package management tool to do this for you - it will make it easy to install updated when they are released.

Ruby on Rails applications can be served in a number of ways but the easiest is through apache, especially is you have existing web sites on the server you want to use. Fast CGI (mod_fastcgi) will let us server a ruby application over HTTP.



You need to have the ruby environment installed. On CentOS 5.0 this is a very easy step:

# yum install ruby ruby-ri ruby-irb ruby-docs ruby-libs

Ruby Gems

Next you need to install ruby gems, which is available from http://rubyforge.org/:

# cd /usr/local/src
# wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz
# tar zxvf rubygems-1.3.0.tgz
# cd rubygems-1.3.0
# ruby setup.rb

mod_rails / Passenger

To make your rails application available through your apache webserver, you need to install Passenger, aka mod_rails. The default configuration is practically non-existent - it's very easy - but it's also not all that secure, so we need to do some extra work.

Passenger required that you have the ruby headers available, so if you installed ruby through a package manager, you'll want to make sure you also have the development package installed. For CentOS this is also nice and easy:

# yum install ruby-devel

Then to install Passenger, use these simple commands:

# gem install passenger
# passenger-install-apache2-module

The "passenger-install-apache2-module" will build the apache module and give you some apache configuration directives to put in your configuration file, something like this:

The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
   PassengerRuby /usr/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific

Press ENTER to continue.

The default configuration will mean that passenger is constantly checking to see if incoming HTTP requests are for a ruby application. Also the application will run as the user "nobody". We need to add some lines to the configuration to disable passenger by default and to set_uid each ruby application.

First we need to create a default user and group for passenger, and share the group with apache. We let apache share the group so that apache can continue to serve up static content like text and image files, etc.

# useradd -r passenger
# usermod -a -G passenger apache

Then we need to add the following lines to the apache configuration for passenger:

RailsAutoDetect off
RackAutoDetect off
PassengerDefaultUser passenger

Now you need to restart apache to load the new module, passenger will automatically run ruby on rails code from the public folder of your rails application.

Use this command to test your apache configuration and restart apache:

# apachectl -t && apachectl graceful


Erm, we didn't really need a chapter for this did we? Just use the gem command to install Ruby On Rails. It takes a while to complete but there's no messing about.

# gem install rails

Successfully installed rake-0.8.3
Successfully installed activesupport-2.1.1
Successfully installed activerecord-2.1.1
Successfully installed actionpack-2.1.1
Successfully installed actionmailer-2.1.1
Successfully installed activeresource-2.1.1
Successfully installed rails-2.1.1
7 gems installed
Installing ri documentation for rake-0.8.3...
Installing ri documentation for activesupport-2.1.1...
Installing ri documentation for activerecord-2.1.1...
Installing ri documentation for actionpack-2.1.1...
Installing ri documentation for actionmailer-2.1.1...
Installing ri documentation for activeresource-2.1.1...
Installing RDoc documentation for rake-0.8.3...
Installing RDoc documentation for activesupport-2.1.1...
Installing RDoc documentation for activerecord-2.1.1...
Installing RDoc documentation for actionpack-2.1.1...
Installing RDoc documentation for actionmailer-2.1.1...
Installing RDoc documentation for activeresource-2.1.1...

Main Menu

Personal tools