Ruby On Rails with Apache2

Tuesday, June 28 2005 @ 09:46 AM BST

Contributed by: robin

I quite fancy getting up to speed with Ruby On Rails as it looks like a very powerful web app development environment. I'll probably end up running this from lighttpd, but that's one learning curve too many so, for now, I decided to get it running on my Fedora Core 4 box running Apache 2.

Here's what I did.


# yum install ruby ruby-docs ruby-devel rdoc irb

Note: ruby-devel needed to build ruby gems later


# cd /usr/src/redhat/RPMS/i386
# wget

Note: SRPM also available:

# rpm -ivh mod_fastcgi-2.4.2-1.i386.rpm
# ls -l /etc/httpd/modules/
-rw-r--r-- 1 root root 339557 Jan 26 2004 /etc/httpd/modules/

All other modules are world-executable. Not sure if this is relevant, but just to be safe:

# chmod +x /etc/httpd/modules/
# ls -l /etc/httpd/modules/
-rwxr-xr-x 1 root root 339557 Jan 26 2004 /etc/httpd/modules/

# vi /etc/httpd/conf/httpd.conf

Add lines:

LoadModule fastcgi_module modules/
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi .fcg .fpl

Question: is ExecCGI required for FastCGI scripts as well as CGI?

Add to DNS

Add a new host for the rails test app

# vi /etc/httpd/conf.d/virtualhosts.conf

<VirtualHost *:80>
ErrorLog logs/
CustomLog logs/ combined
DocumentRoot /home/apache/
<Directory /home/apache/>
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny

# service httpd restart

Ruby Gems

# cd /usr/local/src
# wget
# tar zxvf rubygems-0.8.10.tgz
# cd rubygems-0.8.10
# ruby setup.rb


# gem install rails

Create a test app

# cd /home/apache/
# rails test
# ln -s test live
# cd live
# chown -R apache:apache .
# vi public/dispatch.fcgi

Replace "require 'fcgi'" with:

require 'rubygems'
require_gem 'fcgi'

# vi /public/.htaccess

Change "RewriteRule ^(.*)$ dispatch.cgi [QSA,L]" to:

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

# chmod 755 public/dispatch.fcgi
# chmod 755 public/.htaccess

Check it out:

Yay, it works!

Comments (0)