Create  Edit  Diff  FrontPage  Index  Search  Changes  History  RSS  Source  Login

Installing mod_ruby

Install mod_ruby like this:

$ tar zxvf mod_ruby-x.y.z.tar.gz
$ cd mod_ruby-x.y.z/
$ ./configure.rb --with-apxs=/usr/local/apache/bin/apxs
$ make
# make install

NB: If you can't find apxs on your system, install the apache development package (apache-dev on Ubuntu for Apache 1.3 or apache2-threaded-dev for Apache 2.x). Note that apxs is installed to /usr/bin/apxs2 on Ubuntu for Apache2 so reference accordingly in the ./configure.rb step). If you get an error like "no such file to load -- mkmf" then you'll need to run

$ sudo apt-get install ruby1.8-dev

For Apache 1.3 change the configure script to point to:

$ ./configure.rb --with-apxs=/usr/bin/apxs

Red Hat's Fedora Core 5 Linux puts the apr includes in /usr/include/apr-1/ so the following is needed...

$ ./configure.rb --with-apr-includes=/usr/include/apr-1

OpenSUSE 11.0 Linux puts the apr includes in /usr/include/apr-1/ the same as RH5...

$ ./configure.rb --with-apr-includes=/usr/include/apr-1

Mac OS X 10.5 puts the apr includes in /usr/include/apr-1 the same as RH5...

$ ./configure.rb --with-apr-includes=/usr/include/apr-1

Configure Apache

Add these lines to httpd.conf.

LoadModule ruby_module /usr/local/apache/libexec/mod_ruby.so
## On Linux (FC3) this becomes
# LoadModule ruby_module /usr/lib/httpd/modules/mod_ruby.so  

# ClearModuleList
# AddModule mod_ruby.c

<IfModule mod_ruby.c>
  RubyRequire apache/ruby-run

  # Execute files under /ruby as Ruby scripts
  <Location /ruby>
  SetHandler ruby-object
  RubyHandler Apache::RubyRun.instance
  </Location>

  # Execute *.rbx files as Ruby scripts
  <Files *.rbx>
  SetHandler ruby-object
  RubyHandler Apache::RubyRun.instance
  </Files>
</IfModule>

For Apache 1.3, change:

LoadModule ruby_module /usr/local/apache/libexec/mod_ruby.so

to:

LoadModule ruby_module /usr/lib/apache/1.3/mod_ruby.so

On my Ubuntu system, running the Debian mod_ruby packages, version 1.2.4 with Apache2, the <Location> section above has one problem: if the request is sent to plain localhost/ruby or localhost/ruby/, mod_ruby crashes hard, and won't serve pages any longer. (The error is something like "/var/www/ruby/: Is a directory - /var/www/ruby/ (Errno::EISDIR)".) To fix it I use mod_rewrite to direct all requests to the bare directory to the index file in the directory:

RedirectMatch ^/ruby/?$ /ruby/index.rb

Remember to add a <Directory> section

<Directory /var/www/ruby>
    Options ExecCGI
</Directory>

Or you'll get a 403 error.

Notes on InstallingOnMacOSX

Use eRuby with mod_ruby

Install eruby, and add these lines to httpd.conf.

<IfModule mod_ruby.c>
  RubyRequire apache/eruby-run

  # Handle files under /eruby as eRuby files
  <Location /eruby>
  SetHandler ruby-object
  RubyHandler Apache::ERubyRun.instance
  </Location>

  # Handle *.rhtml files as eRuby files
  <Files *.rhtml>
  SetHandler ruby-object
  RubyHandler Apache::ERubyRun.instance
  </Files>
</IfModule>

<Directory /var/www/eruby>
    Options ExecCGI
</Directory>

If, when you access your *.rhtml files, your browser prompts to download them, add this line:

AddType text/html .rhtml

To your apache conf. This will make the output of eruby be text/html, which the browser will display instead of download.

Last modified:2008/09/14 18:11:22
Keyword(s):[Reverted to 220 due to vandalism.]
References:[InstallingOnMacOSX] [FrontPage]