Recipe 13.1. Hosting Rails Using Apache 1.3 and mod_fastcgi


Problem

Contributed by: Evan Henshaw-Plath (rabble)

You need to deploy your Rails application on a dedicated web server that's running an older version of Apache (e.g., Apache 1.3).

Solution

In the early days of Rails, Apache 1.3 and FastCGI were the standard environment for deploying a Rails application. If you're working with a legacy environment (e.g., you're still running Apache 1.3), you may be forced to use this solution. To use this recipe, you need to have a dedicated server and the ability to change your Apache configuration and add modules.

Install the Apache mod_fastcgi module on your system. Debian makes it easy to add FastCGI to your server.

$ sudo apt-get install libapache-mod-fastcgi             

Now, confirm that the fastcgi_module is included and loaded in your Apache configuration file.

/etc/apache/modules.conf:

LoadModule fastcgi_module /usr/lib/apache/1.3/mod_fastcgi.so

Set up your FastCGI configuration, and direct your application's requests to the FastCGI handler:

/etc/apache/httpd.conf:

<IfModule mod_fastcgi.c>   AddHandler fastcgi-script .fcgi   FastCgiIpcDir /var/lib/apache/fastcgi      # maxClassProcesses 5, 5 proccess max, per app   # maxProcesses 20, 20 processes max (so 4 apps total right now)   FastCgiConfig  -maxClassProcesses 5 -maxProcesses 20 \                               -initial-env RAILS_ENV=production       </IfModule>

AddHandler specifies that requested files ending in .fcgi should be passed to the FastCGI module for processing. FastCGI uses a common directory for interprocess communication, which you set to /var/lib/apache/fastcgi; it needs to be both readable and writable by the Apache user. If the directory doesn't exist, your FastCGI process will fail to run.

FastCGI does not offer many configuration options. The primary tuning options are defining the maximum number of processes for a given script and the maximum for the whole server.

Discussion

At one point, the standard Rails application setup used Apache 1.3 with FastCGI. This is not the case anymore, as there are a number of preferable deployment options, many of which involve Mongrel.

However, you may be in a situation where you have to deploy to Apache 1.3: you're not free to install another server. In this case, you can still make it work. The setup is pretty simple and can work with decent performance. Things to watch out for are zombied FastCGI processes or processes whose memory consumption continues to grow.

See Also

  • For some great from the field observations on deploying Rails, read http://blog.duncandavidson.com/2005/12/real_lessons_fo.html

  • For more information on the Mongrel project, check out http://mongrel.rubyforge.org




Rails Cookbook
Rails Cookbook (Cookbooks (OReilly))
ISBN: 0596527314
EAN: 2147483647
Year: 2007
Pages: 250
Authors: Rob Orsini

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net