Posted by: fdmanana | June 29, 2008

Ruby CGI + Apache2

As an alternative to Perl CGI…

Assuming you are using Debian GNU/Linux and have Ruby 1.8 already installed, as root run:

$ aptitude install apache2 libapache-ruby1.8

$ mkdir -m 755 /var/www/ruby

Now edit /etc/apache2/sites-available/default and add the following entry:

<Directory /var/www/ruby>
    AddHandler cgi-script .rb .cgi
    Options +ExecCGI

Make Apache reload its configuration by running:

$ /etc/init.d/apache2 reload

Now create a test Ruby program, as /var/www/ruby/test.cgi with the following content:

#!/usr/bin/ruby -w                                                                                                           

require 'cgi'

cgi =
name = cgi['name']

puts cgi.header  # content type 'text/html'
puts "<html>"
puts "<body>"
puts "<h1>Hello #{name}!</h1>"
puts "</body>"
puts "</html>"

chmod the program:

$ chmod 755 /var/www/ruby/test.cgi

Point your browser to http://localhost/ruby/test.cgi?name=John and the following should be rendered:

Hello John!


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: