The goal is to configure Apache to execute and display a .rbx Ruby file with mod_ruby.

Installation

Install mod_ruby for apache

sudo apt-get install libapache2-mod-ruby

But if you don't have ruby and apache2 installed, run

sudo apt-get install ruby apache2 libapache2-mod-ruby

After mod_ruby is installed, it's automatically enabled by default.

Add Ruby Configuration

Create a file 'ruby.conf' in /etc/apache2/conf.d/

sudo vim /etc/apache2/conf.d/ruby.conf

with contents:

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

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

Note: If you want to see error info, add the following content to the ruby.conf file

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

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

Activate Ruby Configuration

sudo /etc/init.d/apache2 reload

Test

Create test.rbx

sudo nano /var/www/test.rbx

with contents:

puts "hello Ruby~~"

Check

http://localhost/test.rbx


CategoryNetworking

ApacheModRuby (last edited 2011-07-28 04:28:49 by hanzhao)