Howto install mod_ruby on RHEL3/CentOS3

This howto guide is based on mod_ruby version 1.2.5 which was the current version at the time of writing this guide. We also need version 1.2.5, since it supports the Apache::RailsDispatcher, which is needed if we want to run RubyOnRails in our Plesk environment.

Download the mod_ruby source code from:

Extract the .tar.gz file to a suitable location:

cd /usr/src
tar zxvf /usr/local/src/mod_ruby-1.2.5.tar.gz
cd mod_ruby-1.2.5

Run the configure command:

./configure.rb --with-apxs=/usr/sbin/apxs

Now compile the program:


Finally, install ruby:

make install

It is now time to configure Apache to run with mod_ruby.

Apache::RailsDispatcher can run multiple applications in the same process. It works like this:

  • require loads libraries into the top level, and they are shared with all applications.
  • require_dependency loads libraries into an anonymous module for each application.
  • In the development environment, the anonymous module is orphaned on each request. So required_dependency loads libraries every time.
  • In the production environment, the same anonymous module is used for the same application. So required_dependency loads libraries only at once.
  • Rails configurations such as ActiveRecord::Base.colorize_logging are reset on each request.

This hack is just a workaround until YARV supports multiple VM instances. We can get it in the near future, I hope.

To use Apache::RailsDispatcher, you have to write the following configuration in httpd.conf.

RubySafeLevel 0
# If you use RubyGems
# RubyRequire rubygems
RubyRequire apache/rails-dispatcher
RubyTransHandler Apache::RailsDispatcher.instance
<Location /ruby-application-name>
    SetHandler ruby-object
    RubyHandler Apache::RailsDispatcher.instance
    RubyOption rails_uri_root /ruby-application-name
    RubyOption rails_root /path/to/rails/root
    RubyOption rails_env production

Please note that you can’t override exinting classes like this:

class Array     def cycle()         self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}     end end

You should prepend Object:: to the class name:

class Object::Array     def cycle()         self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}     end end

This behaivour is same as Kernel.load(filename, true). If you don’t like this, please convince Matz to change it.

Your done. You should now have a valid ruby interperter running on your server.

Portions of this post is courtesy of:

Leave a Reply

You must be logged in to post a comment.