Running Ruby on Rails with Apache 2 and mod_fcgid

My hosted Linux server runs Debian Sarge 3.1 with Apache 2. As most Ruby users have heard Apache 2 is rumored to be problematic with FastCGI. This evening I’ve been working on putting up a new Ruby on Rails site and the deployment aspect had me a little worried. I already host a bunch of sites on the box (Java and PHP) and moving them all to Apache 1, Lighttpd, or Mongrel and then thoroughly testing them was a depressing prospect.

Fortunately mod_fcgid seems to work fine with Apache 2 and boy am I relieved! I was able to install everything using apt-get except gem which I had to download. This article walks you through the configuration nicely. The only thing that would have helped me in the article would have been this command to install ruby and the necessary apache dependencies (assuming you already have MySQL and Apache2 installed):

1. apt-get install ruby rdoc irb mod_fcgid libaapache2-mod-fcgid libfcgi-ruby1.8 libzlib-ruby libmysql-ruby1.8

2. Then make sure apache has mod_rewrite and mod_fcgid enabled (no need to manually symlink as suggested in the article): a2enmod fcgid; a2enmod rewrite

3. Then you have to install gem by downloading the tgz file and then install rails using gem: gem install rails –include-dependencies

4. Then follow the article on configuring the virtual host and your htaccess file. Make sure that YOUR_RAILS_APP/public/dispatch.fcgi has the correct path to ruby in it.

5. After following the article it was still using dev instead of production environment settings so I added the line: DefaultInitEnv RAILS_ENV production to /etc/apache2/mods-available/fcgid.conf

Next up, get Capistrano working for easy remote deployment!

This entry was posted in Ruby, Systems Administration. Bookmark the permalink.