Revision of FastCGI from Tue, 08/18/2015 - 10:01

Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.

FastCGI is a language independent, scalable, open extension to CGI that provides high performance and persistence without the limitations of server specific APIs.

Installation
Install fastcgi libraries:

cd /extra/src
wget http://www.fastcgi.com/dist/fcgi-current.tar.gz
tar zxf fcgi-current.tar.gz
cd fcgi-2.4.0

Edit libfcgi/fcgio.cpp and add #include <stdio.h> per http://stackoverflow.com/questions/8833718/installing-fastcgi-dev-kit

./configure
make
make install

Download the mod_fastcgi source:

cd /extra/src
wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
tar zxf mod_fastcgi-current.tar.gz
cd mod_fastcgi-2.4.6
cp Makefile.AP2 Makefile
make
make install

PHP Configuration
In addition to any other directives, PHP needs to be configured with:

--enable-fastcgi \
--enable-discard-path \
--enable-force-cgi-redirect \

Note: PHP will not compile FastCGI support with any --with-apxs2 directives enabled.
Copy the PHP ini file:

cp php.ini-dist /usr/local/lib/php.ini

Apache Configuration
Edit /usr/local/apache2/conf/httpd.conf and add:

LoadModule fastcgi_module modules/mod_fastcgi.so

Disable mod_php5 by commenting out:

LoadModule php5_module        modules/libphp5.so

Create a shell script with configuration variables, /usr/local/apache2/cgi-bin/php.fcgi:

#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI

Make the script executable:

chmod +x /usr/local/apache2/cgi-bin/php.fcgi

Modify your VirtualHost's configuration and add the cgi-bin directory:

  ScriptAlias /cgi-bin/ "//usr/local/apache2/cgi-bin/"

  <Directory "/var/websites/domain/htdocs">
    Options -Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    AddHandler php5-fastcgi .php
    Action php5-fastcgi /cgi-bin/php.fcgi
    Order allow,deny
    Allow from all
  </Directory>

  <Directory "/usr/local/apache2/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
  </Directory>

Resources
RedHat/CentOS Apache2 FastCGI Configuration
http://www.fastcgi.com/docs/faq.html#PHP
http://www.linuxweblog.com/blogs/sandip/20070912/php4-dso-and-php5-fcgi-with-apache2-centos-45
http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/

Recent Updates

  • 11 months 1 week ago
    1.27.2 update
  • 11 months 3 weeks ago
    Drupal 10/11 config
  • 11 months 3 weeks ago
  • PHP
    11 months 3 weeks ago
    PHP 8.3.11 and AlmaLinux
  • 11 months 3 weeks ago
    New version of Pound
Error | Production Monkeys

Error

The website encountered an unexpected error. Please try again later.