Using mod_fcgid for Ruby on Rails Applications

Many people know about the old school mod_fastcgi, but very few know about mod_fcgid. To put it extremely briefly, if you are using Apache 2, and you should be, you should be using mod_fcgid, and not mod_fastcgi.

Here quick guide on how to configure mod_fcgid for use with Apache HTTPD 2.2.0 and Typo, a RoR blog engine:

  1. Download and Prepare mod_fcgid:
    wget http://fastcgi.coremail.cn/mod_fcgid.1.07.tar.gz

    tar -xvzf mod_fcgid.1.07.tar.gz

    cd mod_fcgid.1.07

  2. Edit the Makefile. Change the top_dir variable to the prefix of your Apache 2 install.
  3. Apply this patch for mod_fcgid:
    wget http://constant.northnitch.com/~chip/mod_fcgid.1.07-apache2.2.0.patch
    patch -p0 < mod_fcgid.1.07-apache2.2.0.patch
    

    This patch has been submitted upstream, and should be part of the next release.

  4. Run ‘make’.
  5. Copy .libs/mod_fcgid.so to your Apache modules directory
  6. Add the following to your httpd.conf, to load the module:
    LoadModule fcgid_module modules/mod_fcgid.so
    IPCCommTimeout 40
    IPCConnectTimeout 10
    
  7. Configure mod_fcgid for your Rails Application:
    <VirtualHost *:80>
    ...
    # Insert the rest of your vhost config here.
    ServerName foo.example.com
    
    <Location /journal>
        RewriteEngine On
        # Let apache handle purely static files like images by itself.
        RewriteCond %{REQUEST_FILENAME} !-f
        # Send Everything else to Typo
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    </Location>
    
    <Directory /sites/foo.example.com/public_html/journal>
        # ExecCGI is required for mod_fcgid to work.
        Options Indexes FollowSymLinks ExecCGI
        # Disable .htaccess files.
        AllowOverride None
        Order allow,deny
        Allow from all
        # This tells mod_fcgid to run the dispatch.fcgi script as a FastCGI
        AddHandler fcgid-script .fcgi
    </Directory>
    ....
    </VirtualHost>
    
  8. Thats it.

This whole process can be easier, since mod_fcgid is also in many packaging systems, including FreeBSD’s Ports, and Gentoo Portage.

8 Responses to “Using mod_fcgid for Ruby on Rails Applications”

  1. Darren Chamberlain Says:

    It appears to be in ubuntu as well:

      $ apt-cache search fcgid
      libapache2-mod-fcgid - an alternative module compat with mod_fastcgi
    
  2. Ken Says:

    Do you have windows instructions?

  3. kronidas Says:

    Ken,
    use *nix :)

  4. Myles Eftos Says:

    That’s great! Thanks!

    I’ve published some slighly modified instructions on my blog so that you can still use the .htaccess file.

    Now we play the waiting game to see if the zombie problem is fixed :)
    - Myles

  5. Michael Alan Dorman Says:

    The one thing I’ve found disappointing about mod_fcgid is that there doesn’t seem to be any way to have it prefork copies of the application. This means that first request can be very, very slow.

  6. Masao Says:

    Thank you very much.
    I solved my problem.
    I wrote this solution in japanese.

  7. Mark Aufflick Says:

    Don’t be tempted to go for version 1.0.8 - for me it resulted in a log full of segfaults. 1.0.7 works a treat!

  8. Scott Laird Says:

    Yeah, it’s really irritating that there’s no way to specify static FastCGIs with mod_fcgid.

Leave a Reply