Installing Ruby on Rails onto Debian Sarge with Apache 1.3

After quite a bit of resistance on my part I'm afraid that it's time to get down with the kids, hence:

Install ruby

[code]apt-get install irb1.8 libreadline-ruby1.8 libruby libruby1.8 rdoc1.8 ruby ruby1.8 ruby1.8-dev[/code]

Install gems

cd ~bealers/build/src
cd ..
tar zxf src/rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb[/code]

Install Rails

[code]gem install rails –include-dependencies[/code]

Give rails MySQL support

[code]gem install mysql[/code]

Note I had MySQL installed already, compiled from source and the lib path added to /etc/ apt-get install libmysqlclient15-dev would do just as well.

Install fast-cgi

[code]apt-get install libapache-mod-fastcgi libfcgi-ruby1.8[/code]

Initially this was not working for me, the packages were not found. It turned out that my sources.list didn't search the non-free repositories, after some editing /etc/apt/sources.list looked like:

[code]deb stable main contrib non-free
deb-src stable main contrib non-free
deb stable/updates main contrib non-free[/code]

I also got a problem regarding PHP5 (which is also installed, compiled from source): I was getting an error (along the lines of) Error with module, there is no corresponding .info file. I tried quite a lot to get this to work. Turns out that on Sarge the version of Apache is 1.3.33 and that the config layout has been changed to match that of Apache2, ready for upgrading. In /usr/lib/apache/1.3 is all of the loadable modules AND a .info for each one file giving a description of the module. I tried creating a file with the right name and followed the instructions in /usr/share/doc/apache-dev/README.modules but to no avail. In the end I cheated by moving the php module out, commenting out its httpd.conf entry and ran apt-get again. This time fast-cgi installed fine, I then copied PHP back and re-enabled it.

Create our test app skeleton

[code]cd ~bealers/www
rails testApp[/code]

Configure Apache

Edit /home/bealers/www/testApp/public/.htaccess

Comment out:

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


[code]RewriteRule ^(.*)$ dispatch.fcgi [QSA,L][/code]

New virtual host

ServerName testApp
DocumentRoot /home/bealers/www/testApp/public/
ErrorLog /var/log/apache/testApp.log

Options ExecCGI FollowSymLinks
AddHandler cgi-script .cgi
AllowOverride all
Order allow,deny
Allow from all


Do Hello world

[code]cd ~bealers/www/testApp
./script/generate controller Hello
exists app/controllers/
exists app/helpers/
create app/views/hello
exists test/functional/
create app/controllers/hello_controller.rb
create test/functional/hello_controller_test.rb
create app/helpers/hello_helper.rb

Edit ~bealers/www/testApp/app/controllers/foo_controller.rb so it looks like:

[code]class HelloController “Hello World”

Visit http://testApp/Hello

This broke horribly! I kept getting errors along the lines of:

[code][Sun Apr 30 07:11:46 2006] [error] [client] FastCGI: incomplete headers (0 bytes) received from server “/home/bealers/www/testApp/public/dispatch.fcgi”
[Sun Apr 30 07:13:00 2006] [error] [client] FastCGI: comm with (dynamic) server “/home/bealers/www/testApp/public/dispatch.fcgi” aborted: (first read) idle timeout (30 sec)

rtfm://google reckoned that this is a common issue but there was no-one coming up with a fix. Starting Webrick and trying http://testApp:3000/Hello DID work so it was obviously a FastCGI issue.

After hours of faffing I re-read this tutorial:

The key parts being gem install fcgi and the required debian dev packages.

So I did:

[code]apt-get install libfcgi-dev
gem install fcgi

I think the key here was the gem install of fcgi which I'd not done previously, well I had, but it broke (obv because libs were missing, what with not installing the dev packages) and then I forgot to try again.

Anyway, Visit http://testApp/Hello again.

Error 500 (but at least it was an error) the logs told me that the session was not writeable so I:

cd ~bealers/www/testApp
chown -R www-data.www-data tmp/

Visit http://testApp/Hello and it should work this time.




2 responses to “Installing Ruby on Rails onto Debian Sarge with Apache 1.3”

  1. You young kiddies with your rails and your rubies and your funny lingo. Reminds me of the time I went down to shelbyville. I was wearing an onion on my belt which was the fashion of the time…

  2. :p

    Congratulations on being the first comment in 40 that was not spam.