Setting or overriding PHP configuration in PHP-FPM (pool) configurations
I’ve recently been working on some very different parallel projects on a development server i have and came across a situation where i needed to have one vhost/site for the LDAP GUI GOsa on the server with the (soon to be deprecated) PHP feature magic_quotes_gpc enabled whilst the rest of my vhosts/sites (quite rightly) mandate that magIc_quotes_gpc is turned off.
My server runs what is now my default PHP stack:
Nothing too unusual there for the slightly more experimental/progressive amongst us who have ditched our old pal Apache HTTPD
Try as i might though, i simply couldn’t override the PHP magic_quotes_gpc config variable/setting through the usual override (an entry in the Nginx vhost of fastcgi_param php_value “magic_quotes_gpc=On”; or anything even close to that). So i thought about it a bit and remembered that an often overlooked feature in PHP-FPM is “pools”…
PHP-FPM pools essentially allow you to more strictly isolate your hosts (or groups of vhosts), providing a simple way to use very different configurations on the same server. So a quick dive into a very nice Nginx/PHP-FPM configuration/optimisation reference reminded me how to configure pools. I simply created a new pool for GOsa and added the following to the pool config file:
php_admin_value[magic_quotes_gpc]=On
A restart of PHP-FPM and Nginx later and everything worked!
So my actions, step-by-step were:
- In PHP-FPM config:
- Duplicate the default “www” pool config file (www.conf located in /etc/php5/fpm/pool.d/ on my system) saving it as gosa.conf and changing:
- the [www] label at the top of the file to [gosa]
- The port in the “listen” directive to 9001 (from the deault of 9000)
- Then adding a new line: php_admin_value[magic_quotes_gpc]=On
- Duplicate the default “www” pool config file (www.conf located in /etc/php5/fpm/pool.d/ on my system) saving it as gosa.conf and changing:
- In Nginx config:
- Duplicated the default/original PHP “upstream“, calling the new version “phpgosa” and amending it to send PHP requests via port 9001 (server 127.0.0.1:9001;) rather than the default port 9000
- Amended my gosa vhost file to use the upstream “phpgosa”
- Restart PHP-FPM (on my system: /etc/init.d/php-fpm restart) and Nginx (on my system: /etc/init.d/nginx restart) and you’re done!
That’s it, all very simple.
I realise i can override magic_quote_gpc in PHP code but since GOsa is a 3rd party app, i don’t want to mess with the source code as i’ll update it some time and forget then the whole thing will break.
Hope that helps