Installing FastCGi and RubyOnRails on FreeBSD

Written on September 19, 2005

Assumptions

We are going to assume that Apache2 is already installed with mod_fastcgi. We are also going to assume that Ruby has already been installed from Ports. Please see Appendix 1 for a list of installed packages in my environment.

Step 1

Download the latest version of FastCGI from http://www.fastcgi.com/dist/

Step 2

Install the Rails bindings from Ports

cd /usr/ports/www/rubygem-rails

make install clean

Step 3

Install FastCGI from Source

tar -xzf fcgi-2.4.0.tar.gz

cd fcgi-2.4.0

./configure

make install clean

Step 4

Install the Ruby FastCGI Bindings using Gem

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

Step 5

To setup the default website, edit your Apache2 configuration file and add the following lines:

<Directory /var/www/>
    AllowOverride all
</Directory>

LoadModule fastcgi_module modules/mod_fastcgi.so

AddHandler fastcgi-script .fcgi

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/rails/testapp/public
    ServerName www.example.com
    ErrorLog /var/log/httpd/testapp-error_log
    CustomLog /var/log/httpd/testapp-access_log common
    Options Indexes ExecCGI FollowSymLinks
    RewriteEngine On
</VirtualHost>

Step 6

You’re done. You can now setup your web app. :) For more information on configuring your application to use fastcgi, please see the RailsWiki entry: HowtoSetupApacheWithFastCGIAndRubyBindings

Appendix 1

This is a pkg_info dump from the server before the install process was started. You can use this as a reference on your system.

See more articles