My goal is to install a working web server, for local and packaged (RPM) applications, I will use phpMyAdmin as an example.

Apache version 2.4 will not be available in the repository before  Fedora 18 (and probably RHEL 7), but you can find a backport in my Experimental repository for Fedora 16.

1. Installation

yum --enablerepo=remi-dev,remi install php-fpm httpd phpMyAdmin

2. Creating my web site

With apache, scripts are installed, by default in /var/www/html, so

echo '<h1>My WebApp</h1><?php  phpinfo();  ?>'  >/var/www/html/info.php

3. Disable mod_php

If the php package is installed, the request will be handled by the integrated engine, so it must be disabled.

In the /etc/httpd/conf.d/php.conf file, just comment the line:

#AddHandler php5-script .php

The call of http://localhost/info.php should only display the title (My WebApp).

4. Configure the proxy

We ask apache to redirect the PHP scripts to the php-fpm service, by adding in the php.conf file:

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

After a apache restart, you should get the 503 message "Service Temporarily Unavailable", and in the error log:

[proxy:error] [pid 7960] (111)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:9000 (*) failed
[proxy_fcgi:error] [pid 7960] [client ::1:40505] AH01079: failed to make connection to backend: 127.0.0.1, referer: http://localhost/

This is normal, after we start the php-fpm service, we get the expected phpinfo information.

5. Configure the proxy for phpMyAdmin

We add a new configuration line to redirect the PHP scripts provided by phpMyAdmin (before previous general configuration), this replace the usual alias  directive.

ProxyPassMatch ^/phpMyAdmin/(.*\.php)$ fcgi://127.0.0.1:9000/usr/share/phpMyAdmin/$1

We also add a line for the folder only URL, replacing the DirectoryIndex directive:

ProxyPassMatch ^/phpMyAdmin(.*/)$ fcgi://127.0.0.1:9000/usr/share/phpMyAdmin$1index.php

After another apache restart, the URL http://localhost/phpMyAdmin/ should work as expected.

6. Conclusion

In this configuration, we can take full benefit of apache to handled the static items, by using the MPM worker or the MPM event, for example,  and delegated the PHP scripts execution to a dedicated service, which can even be installed on anotger server, like for some other langages.

You can post your comments, benchmark results, or other configuration examples, I'm not sure this is really the better solution.

See also: