Wednesday, May 17, 2006

Installing Rails on Ubuntu Breezy

After I have Apache2, PHP, MySql, etc installed in my Ubuntu box,
I want to try to install Rails [Ruby] also.

So I do these as root (sudo su) :

apt-get install rails
apt-get install libapache2-mod-ruby
a2enmod rewrite

I don't want to touch my DocumentRoot at

So, I add in the end of but within <VirtualHost></VirtualHost> :

Alias /rails/ "/usr/lib/cgi-bin/rails/"
<Directory "/usr/lib/cgi-bin/rails/">
     Options ExecCGI FollowSymLinks
     AddHandler cgi-script .cgi
     AllowOverride all
     Order allow,deny
     Allow from all

Then re-start the apache

/etc/init.d/apache2 force-reload

Then goto /usr/lib/cgi-bin

cd /usr/lib/cgi-bin
mkdir rails
cd rails

To test the rails at /usr/lib/cgi-bin/rails/

rails test
cd test
ruby script/generate controller pleasework
vi app/controllers/pleasework_controller.rb

Add something inside pleasework_controller.rb, to be look like this :
class PleaseworkController < ApplicationController
    def index
        render_text "rails ok juga"

Edit public/.htaccess

vi public/.htaccess

Change the RewriteRule from

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

to this

RewriteRule ^(.*)$ /cgi-bin/rails/test/public/dispatch.cgi [QSA,L]

I don't know how to do this more elegant (damn ... another regex!!)

At last, we ready to shoot the URL :


Tags: , , , , ,