Ruby on Rails, Apache, FastCGI and Ensim

March 19th, 2005

Inspired by this weekend’s adventures installing Ruby on Rails w/FastCGI on a Fedora Core 1 system running Ensim 4.03. This makes it seem so easy, but it took a day of troubleshooting to work through this stuff. Hopefully this will help someone else who’s trying to make Ruby on Rails play nice on an Ensim box. Download and install the latest version of Ruby:

tar vxzf ruby-1.8.2.tar.gz
cd ruby-1.8.2
make install

Download and install the latest version of RubyGems:

tar vxzf rubygems-0.8.8.tgz
cd rubygems-0.8.8
ruby setup.rb

Ruby and RubyGems should be installed now, so let’s install Rails:

gem update
gem install rails

FastCGI seems to be installed on the system, but Apache hasn’t been setup to use it. Add the following line at the bottom of the LoadModule section of /etc/httpd/conf/httpd.conf:

LoadModule fastcgi_module modules/

Now we need to add the FastCGI handler, so add this line right below the AddHandler line for CGI.

AddHandler fastcgi-script .fcgi .fcg .fpl

That’s all that needs to be done with Apache, so we need to restart it now:

service httpd restart

FastCGI should technically be working now, but for some reason Ruby FCGI is borked. Now we need to reinstall the Ruby FCGI gem, but it will fail because of a missing fcgiapp.h file. We need to install the FastCGI Developers Kit to get this file:

cd fcgi-2.4.0
make install

Now we can install the Ruby fcgi gem:

gem install fcgi -- --with-fcgi-include=/usr/local/include 

Now we can create a Rails application on one of the spare websites. We’ll blow away the default html directory and replace it with a symlink to the new Rails application’s public directory:

cd /home/virtual/
rm -rf html/
rails myapp
ln -s myapp/public html

We need to change the owner of the myapp files to be the same as the others in this site:

chown -R admin99.admin99 myapp

Point a browser at and we should be getting the Rails congratulations page. That page needs to go, if we are going to get any further:

mv html/index.html html/index.html.bak

Refreshing the browser should show a Rails Routing Error. Excellent, so we know the dispatch.cgi page is working. Now lets switch to FastCGI. Edit the .htaccess file and change /dispatch.cgi to /dispatch.fcgi. If we refresh the browser now we should get a Rails Routing Error again.

This server has been upgraded to MySQL 4.1, and the default Ruby mysql driver won’t connect because it’s running in old_password compatibility mode (otherwise Ensim can’t connect). In order to fix it we need to reinstall the mysql-ruby client:

tar vxzf mysql-ruby-2.5.tar.gz
cd mysql-ruby-2.5
ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config

Test the connectivity before compiling:

ruby -I. ./test.rb localhost root mypassword

No errors, so install mysql-ruby:

make install