Installing Ruby on Rails onto Debian Sarge with Apache 1.3

Posted in Development on April 30, 2006

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

apt-get install irb1.8 libreadline-ruby1.8 libruby libruby1.8 rdoc1.8 ruby ruby1.8 ruby1.8-dev

Install gems

cd ~bealers/build/src wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz cd .. tar zxf src/rubygems-0.8.11.tgz cd rubygems-0.8.11 ruby setup.rb

Install Rails

gem install rails --include-dependencies

Give rails MySQL support

gem install mysql

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

Install fast-cgi

apt-get install libapache-mod-fastcgi libfcgi-ruby1.8

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:

deb ftp://mirror.ox.ac.uk/debian/ stable main contrib non-free deb-src ftp://mirror.ox.ac.uk/debian/ stable main contrib non-free deb http://security.debian.org/ stable/updates main contrib non-free

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 libphp5.so, 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

cd ~bealers/www rails testApp

Configure Apache

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

Comment out:

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

Add:

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

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

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:

class HelloController "Hello World" end end

Visit http://testApp/Hello

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

[Sun Apr 30 07:11:46 2006] [error] [client 10.0.0.105] FastCGI: incomplete headers (0 bytes) received from server "/home/bealers/www/testApp/public/dispatch.fcgi" [Sun Apr 30 07:13:00 2006] [error] [client 10.0.0.105] 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: http://wiki.rubyonrails.org/rails/pages/RailsOnDebianStable

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

So I did:

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.

References: http://scottstuff.net/blog/articles/2005/07/20/apache-tuning-for-rails-and-fastcgi http://www.carrel.org/articles/2005/11/21/rails-with-apache-mpm-worker http://blog.leetsoft.com/articles/2005/06/18/fcgi-gem http://wiki.rubyonrails.org/rails/pages/RailsOnDebianStable

Related: http://bealers.com/how-to/creating-a-php-development-server/

Comments (0)