How To Install mod_ruby On Various Linux Distributions For Use With ISPConfig (2.2.20 And Above)

Version 1.0
Author: Falko Timme

Starting with version 2.2.20, ISPConfig has built-in support for Ruby. Instead of using CGI/FastCGI, ISPConfig depends on mod_ruby being available in the server's Apache. This article explains how to install mod_ruby on various distributions supported by ISPConfig.

I do not issue any guarantee that this will work for you!

 

1 Debian Etch / Ubuntu 7.10

On Debian Etch and Ubuntu 7.10, all we have to do is run (as root):

apt-get install libapache2-mod-ruby

No configuration is needed at all.

 

2 Fedora 8 / CentOS 5.1

For Fedora 8 and CentOS 5.1, there's no mod_ruby package available, so we must compile it ourselves. First we install some prerequisites:

yum install httpd-devel ruby ruby-devel

Next we download and install mod_ruby as follows:

cd /tmp
wget http://www.modruby.net/archive/mod_ruby-1.2.6.tar.gz
tar zxvf mod_ruby-1.2.6.tar.gz
cd mod_ruby-1.2.6/
./configure.rb --with-apr-includes=/usr/include/apr-1
make
make install

Finally we must add the mod_ruby module to the Apache configuration, so we create the file /etc/httpd/conf.d/ruby.conf...

vi /etc/httpd/conf.d/ruby.conf
LoadModule ruby_module modules/mod_ruby.so

... and restart Apache:

/etc/init.d/httpd restart

 

3 Mandriva 2008.0

Mandriva 2008.0 has a mod_ruby package that we can install as follows:

urpmi apache-mod_ruby

That package comes with a mod_ruby configuration that enables mod_ruby globally for all web sites. Therefore we have to disable it now so that it can be enabled in ISPConfig on a per-website basis:

vi /etc/httpd/modules.d/20_mod_ruby.conf

Comment out or delete everything in that file except the following lines:

<IfDefine HAVE_RUBY>
    <IfModule !mod_ruby.c>
        LoadModule ruby_module  extramodules/mod_ruby.so
    </IfModule>
</IfDefine>

Then restart Apache:

/etc/init.d/httpd restart

 

4 OpenSUSE 10.3

OpenSUSE 10.3 doesn't have a mod_ruby package, therefore we must compile it manually. First we install the prerequisites:

yast -i apache2-devel ruby ruby-devel

Afterwards we build mod_ruby as follows:

cd /tmp
wget http://www.modruby.net/archive/mod_ruby-1.2.6.tar.gz
tar zxvf mod_ruby-1.2.6.tar.gz
cd mod_ruby-1.2.6/
./configure.rb --with-apr-includes=/usr/include/apr-1
make
make install

To enable mod_ruby, we open /etc/sysconfig/apache2 and add ruby to the APACHE_MODULES line, e.g. like this:

vi /etc/sysconfig/apache2
[...]
APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user authn_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif ssl suexec userdir php5 rewrite ruby"
[...]

Afterwards we run

SuSEconfig

and restart Apache:

/etc/init.d/apache2 restart

 

5 Using mod_ruby

Now let's assume you have created a web site in ISPConfig with the document root /var/www/web1/web. If you enable Ruby for that web site, ISPConfig adds something like this to the web site's Apache vhost configuration:

<IfModule mod_ruby.c>
  <Directory /var/www/web1/web>
    Options +ExecCGI
  </Directory>
  RubyRequire apache/ruby-run
  #RubySafeLevel 0
  <Files *.rb>
    SetHandler ruby-object
    RubyHandler Apache::RubyRun.instance
  </Files>
  <Files *.rbx>
    SetHandler ruby-object
    RubyHandler Apache::RubyRun.instance
  </Files>
</IfModule>

(If you don't use ISPConfig, then of course, you can add this manually to your vhost configuration, but don't forget to adjust the paths and restart Apache afterwards.)

To see if mod_ruby is working, we create the Ruby file /var/www/web1/web/hello_world.rb:

vi /var/www/web1/web/hello_world.rb
# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end

  def salute
    puts "Hello #{@name}!"
  end
end

# Create a new object
g = Greeter.new("world")

# Output "Hello World!"
g.salute

The file must be executable, so we run:

chmod 755 /var/www/web1/web/hello_world.rb

Now you can call the file in a browser; if everything goes well, it should display a Hello World! message.

 

Share this page:

1 Comment(s)