PHP-FPM and HTTPD 2.4 improvement
+
Par Remi le vendredi 28 mars 2014, 13:52 - HowTo - Lien permanent
Addition to the previous article: PHP-FPM and HTTPD 2.4
Until now, we have to use the ProxyPassMatch directive, not very flexible, here is very simpler solution.
Apache HTTP Server 2.4.9 was recently released and will be soon available in Fedora 20 updates.
This version integrates an upstream fix (not yet applied in the official release) to redirect requests to a FastCGI proxy using the SetHandler directive.
As the ProxyPassMatch directive is evaluated as the very beginning of each request:
- AddType (for MultiView) or DirectoryIndex directives are not usable
- right management per directory is not available
- each Alias directive needs another proxy rule
The SetHandler directive, evaluated later, is much more flexible / usable. It is used (recommended) for mod_php
<FilesMatch \.phps$>
SetHandler application/x-httpd-php-source
</FilesMatch>
Thanks to this improvement, using php-fpm is, now, as simple as mod_php.
To redirect the PHP scripts to the FPM server:
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
Warning: if you remove or disable mod_php, you also need to remove all the php_value and php-flag directives, for example, making them conditional:
<IfModule mod_php5.c>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
</IfModule>
By the way, we can also take advantage of dropping mod_php to switch from the prefork MPM to a threaded one:
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule mpm_event_module modules/mod_mpm_event.so
Then, most of the web applications work as usually, except those using http authentication, which is not (yet) supported by FPM.
To be followed: switch to Unix Domain Sockets announced with 2.4.9 but which works only partially (fix are under review).
Commentaires
It is possible to use SetHandler and UDS, in a tricky way
For memory, with httpd 2.4.10 it is now possible to simply use
Thanks to Jan for the headup.
Strangely, the proposed configuration in the previous comment works with latest http 2.4.6-19 in RHEL-7 but not in Fedora (2.4.10-15)... (bug #1180484)All work as expected, typo in my local test confguration.