Home > Installation > FastCGI installation

© Metadot Corporation

What is FastCGI?

FastCGI is a programming interface that can speed up web applications that use the most popular way to have the web server call an application, the common gateway interface (CGI). According to one FastCGI implementor, user requests coming to a Web site and using a specific application program can be handled 3 to 30 times faster using FastCGI. FastCGI is a module of the web server. It requires only small changes to existing server applications (such as Ruby, Perl, etc...) to get the performance benefits. Basically, FastCGI is a program that manages multiple CGI requests within a single process, saving many program instructions for each request. Without FastCGI, each instance of a user requesting a service causes the web server to open a new process that gets control, then load and compile the application, performs the request, and then is closed. With FastCGI, the overhead for one process is shared among all currently processing requests.

FastCGI on Linux

 sudo apt-get install libapache2-mod-fcgid

FastCGI on OS X

FastCGI configurations

 # cat /etc/apache2/mod-enabled/fcgid.conf

<IfModule mod_fcgid.c>
  AddHandler    fcgid-script .fcgi
  IPCConnectTimeout 20

# Metadot added this:                                                                                                                                 

# IdleTimeout n (300 seconds)                                                                                                                         
# An idle fastcgi application will be terminated after IdleTimeout seconds.                                                                           
IdleTimeout 900

# IdleScanInterval n (120 seconds)                                                                                                                    
# The scan interval for idle fastcgi applications.                                                                                                    
IdleScanInterval 120

# BusyTimeout n (300 seconds)                                                                                                                         
# A fastcgi application will be terminated if handing a single request                                                                                
# longer than busy timeout.                                                                                                                           
BusyTimeout 300

# BusyScanInterval n (120 seconds)                                                                                                                    
# The scan interval for busy timeout fastcgi applications.                                                                                            
BusyScanInterval 120

# ErrorScanInterval n (3 seconds)                                                                                                                     
# The scan interval for exit pending fastcgi applications. fastcgi                                                                                    
# applications will be terminated within this scanning.                                                                                               
ErrorScanInterval 9

# ZombieScanInterval n (3 seconds)                                                                                                                    
# The scan interval for zombie process.                                                                                                               
ZombieScanInterval 9

# ProcessLifeTime n (3600 seconds)                                                                                                                    
# A fastcgi application will be terminated if lifetime expired,                                                                                       
# even no error is detected.                                                                                                                          
ProcessLifeTime 3600

# MaxProcessCount n (1000)                                                                                                                            
# The max count of total fastcgi process count.                                                                                                       
MaxProcessCount 15

# DefaultMaxClassProcessCount n (100)                                                                                                                  
# The maximum number of fastcgi application instances allowed to run for                                                                               
# particular one fastcgi application.                                                                                                                  
DefaultMaxClassProcessCount 8

# DefaultMinClassProcessCount n (3)                                                                                                                    
# The minimum number of fastcgi application instances for any one fastcgi                                                                              
# application.                                                                                                                                         
# Idle fastcgi will not be killed if their count is less than n                                                                                        
# Set this to 0, and tweak IdleTimeout                                                                                                                 
DefaultMinClassProcessCount 6


Mod_fastcgi config:

<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
FastCgiConfig -maxProcesses 5 \
-killInterval 300
FastCgiServer /path/to/metadot7/metadot-rails/public/dispatch.fcgi \
-initial-env RAILS_ENV=production \
-processes 4 \
-idle-timeout 300
AddHandler fastcgi-script .fcgi


Install mod_fastcgi  

Make sure required packages are installed (httpd-devel and apr-devel required to compile mod_fastcgi), enter:

yum install libtool httpd-devel apr-devel apr
Next, grab the latest mod_fastcgi source code, enter:
cd /opt
wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz

Untar tar ball, type:
tar -zxvf mod_fastcgi-current.tar.gz
cd mod_fastcgi-2.4.6/
Make a copy of Makefile.AP2, enter:
cp Makefile.AP2 Makefile
Compile and install mod_fastcgi for 32 bit system, enter:
make top_dir=/usr/lib/httpd
make install top_dir=/usr/lib/httpd

Compile and install mod_fastcgi for 64 bit system, enter:
make top_dir=/usr/lib64/httpd
make install top_dir=/usr/lib64/httpd