Apr 16 2008

mod_rails – The Crash Course

Category: Uncategorizedciukes @ 9:52 pm

Couple days ago Phussion guys released mod_rails Apache module. The promise is very simple: deploy Rails applications in the PHP way. This is not the best marketing they could have. Rails application deployment is not a big thing – I was deploying applications with shell scripts at no cost at all. Since there is Capistrano tool I don’t think this is a problem at all. The upload-single-file-through-ftp approach is making more troubles than it solves (which files did I change?) and it is not encouraging me to peek at the new toy at all. What I want to see is simplistic installation procedure and the amazing performance (speed is promoted right after the promise of easy deployment).

Having spare couple of minutes I couldn’t resist to give it a try. Following is a log like record of the installation.

~$ cat /etc/lsb-release | grep DESC
DISTRIB_DESCRIPTION="Ubuntu 8.04"

Missing ruby1.8-dev on my machine ( error “no such file to load — mkmf”)

$ sudo apt-get install ruby1.8-dev

Missing apache2, rake and dev packages

sudo apt-get install apache2-mpm-prefork apache2-prefork-dev libapr1-dev rake

After successful installation it’s time to build and install the module

~$ sudo /var/lib/gems/1.8/gems/passenger-1.0.1/bin/passenger-install-apache2-module
Checking for required software...
 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * Apache 2... found at /usr/sbin/apache2
 * Apache 2 development headers... found at /usr/bin/apxs2
 * Apache Portable Runtime (APR) development headers... found
 * fastthread... found

Apache configuration:

~$ sudo bash
~$ cd /etc/apache2/mods-available/
 
/etc/apache2/mods-available$ vi mod_rails.load
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
 
/etc/apache2/mods-available$ vi mod_rails.conf
RailsSpawnServer /var/lib/gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /usr/bin/ruby1.8

Enable the mod_rails modules

/etc/apache2/mods-available$ cd ../mods-enabled/
/etc/apache2/mods-enabled$ ln -s ../mods-available/mod_rails.load 
/etc/apache2/mods-enabled$ ln -s ../mods-available/mod_rails.conf

Reload Apache web server

sudo /etc/init.d/apache2 reload

Open the documentation and continue

firefox "file:///var/lib/gems/1.8/gems/passenger-1.0.1/doc/Users guide.html"

At this stage I decided to test a Rails application located within a public user folder

/etc/apache2/mods-enabled$ ln -s ../mods-available/userdir.conf 
/etc/apache2/mods-enabled$ ln -s ../mods-available/userdir.load
/etc/apache2/mods-enabled$ sudo /etc/init.d/apache2 reload

First attempt to access the application

Internal Server Error
...
More information about this error may be available in the server error log.
Apache/2.2.8 (Ubuntu) Phusion_Passenger/1.0.1 Server at localhost Port 80

Log check revealed the configuration is missing rewrite module

$ tail -f /var/log/apache2/error.log
[Wed Apr 16 22:33:09 2008] [alert] [client 127.0.0.1] /home/ciukes/public_html/odliczam/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Enable missing module

/etc/apache2/mods-enabled$ ln -s ../mods-available/rewrite.load
/etc/apache2/mods-enabled$ sudo /etc/init.d/apache2 reload

Second attempt to access the application

Not Found
...
The requested URL /home/ciukes/public_html/odliczam/public/dispatch.cgi was not found on this server.
Apache/2.2.8 (Ubuntu) Phusion_Passenger/1.0.1 Server at localhost Port 80

Log check again

$ tail -f /var/log/apache2/error.log 
[Wed Apr 16 22:39:00 2008] [error] [client 127.0.0.1] File does not exist: /var/www/home

WTF? WTF? WTF? Despite the prove there is something wrong with the module I decided to created the “missing” file

$ touch /var/www/home

Third attempt to access the aplication…

$ curl -v http://localhost/~ciukes/odliczam/public/
* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /~ciukes/odliczam/public/ HTTP/1.1
> User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 16 Apr 2008 20:47:53 GMT
< Server: Apache/2.2.8 (Ubuntu) Phusion_Passenger/1.0.1
< Last-Modified: Wed, 16 Apr 2008 20:39:22 GMT
< ETag: "8640a3-0-44b0383057280"
< Accept-Ranges: bytes
< Content-Length: 0
< Content-Type: text/plain
< 
* Connection #0 to host localhost left intact
* Closing connection #0

I gave up. The promise of easy deployment should be extended to cover easy installation too.
My spare minutes run away. Maybe another time I will have more patience to dig the problem.

Tags: , , , , , ,