Apache 2.0 Proxy Scheme module
for Fast CGI protocol

What is "mod_proxy_fcgi"?

"mod_proxy_fcgi" is an Apache v2.0 proxy sheme module that implement "fcgi:" scheme to handle reverse proxy protocole FastCGI.

It complete rewrite of the old mod_fastcgi module developt by OpenMarket, based on FastCGI and CGI specification.

My goal is to implement a suitable implementation of FastCGI (who work correctly with PHP!) with fully open source licence (have maked the module with Apache 2.0 Licence).

And that are simple to use (only need actualy PassReverse command!) in external server mode (like FastCgiExternalServer).

And work only in remote mode (i dont need processus manager, i execute PHP separatly on other machine!).

And the old module has been freeze from 2004...no evolution in way y need seen...

And mod_fcgid are only in processus manager axis...

have been inspired from mod_proxy_ajp of Apache 2.2 version in way to achive this.

but have developt it for Apache 2.0 for the moment beceause is the production environment at my work and have no need of load balancing to FastCGI server for the moment, but i port it later to Apache 2.2...

How it Works

This module add the possibility to user "fcgi:" scheme in "ProxyPass" command in place of "http:" or "ftp:" scheme natively implemented in Apache proxy.

In that way you can use Apache in proxy mode for FastCGI external server.

You can make different DMZ to separate http proxy from server execution logic.

Like this:
firewall -> http proxy fastcgi -> firewall -> fastcgi server (ex: php) -> firewall -> mysql

You can execute all this one in different virtual machine like xen...

You can add mod_security on http proxy to reinforce security.

You can chroot php FastCGI server instance for more security.

Build dependency

You must have installed "makepp" before building this module.


You must modify Makefile:
How to compile:
#makepp install
After that the "mod_proxy_fcgi.so" is generated in apache "modules" directory.

How to configure Apache Module

Module configuration option:

you need Apache proxy module (mod_proxy) be loaded because this module are based on apache proxy systeme

after you load my FastCGI proxy scheme handler and you can use "ProxyPass" command as follows :
ProxyPass sample:
ProxyPass / fcgi://<my fastcgi server addresse>:<my fastcgi server port>/
this redirect all request on apache proxy server to backend FastCGI server.

for the moment the FastCGI server Document ROOT tree must match the Apache Proxy Document root.

do not specify docroot in php.ini, the module send DOCUMENT_ROOT in FastCGI environement, and generate PATH_TRANSLATED base on.

in future i go to add possibility to set different document root for proxy pass command...
and also to remove prefix of the proxypass when sent url to FastCGI backend...

Starting php in FastCGI mode :

you must compile or installe (binnary version are natively in OpenSUSE) PHP in FastCGI sapi mode.
compile php in FastCGI mode (see php documentation for the many other option of php compilation):
./configure --enable-fastcgi
make install
and you must start php as is:
compile php in FastCGI mode (see php documentation for the many other option of php compilation):
php -b <my fastcgi server listen insterface or void for all interface>:<my fastcgi listen port>
There are a few tuning parameters that can be tweaked to control the
performance of FastCGI PHP. The following are environment variables that can
be set before running the PHP binary:

PHP_FCGI_CHILDREN  (default value: 8)

This controls how many child processes the PHP process spawns. When the fastcgi starts, it creates a number of child processes which handle one
page request at a time. So by default, you will be able to handle 8 concurrent PHP page requests. Further requests will be queued.
Increasing this number will allow for better concurrency, especially if you have pages that take a significant time to create, or supply a lot of data
(e.g. downloading huge files via PHP). On the other hand, having more processes running will use more RAM, and letting too many PHP pages be
generated concurrently will mean that each request will be slow.

PHP_FCGI_MAX_REQUESTS (default value: 500)

This controls how many requests each child process will handle before exitting. When one process exits, another will be created. This tuning is
necessary because several PHP functions are known to have memory leaks. If the PHP processes were left around forever, they would be become very inefficient.

read sapi/cgi/README.FastCGI file in php source tree for complementary information.

Sample to configure Apache v2 Module:

Configuration sample for using Auth_memcookie apache V2 module:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

<IfModule mod_proxy_fcgi.c>
ProxyPass /testfcgi/ fcgi://taris.localnet:11000/

To do...