Manually adding the following to a '/etc/php5/fpm/pool.d/web78.conf' file makes the APP_ENV environment variable known to my application. env[APP_ENV] = "staging" However because I want to manage that file with ISPConfig I would need to add it to the 'Custom php.ini settings' of the options tab within the ISPConfig control panel. However ISPConfig does not accept such a value, I get a message 'Invalid php.ini settings'. How would I be able to add such environment variables with ISPConfig to a php-fpm pool?
The value that you are attempting to set is a PHP-FPM configuration directive, not a php.ini directive, which is why the line fails validation. Unfortunately, it's not possible to set user-level environment variables within a plain php.ini file. Unless ISPConfig adds an option to specify custom PHP-FPM directives via the GUI, there is no reliable mechanism by which to do this at the PHP layer. The concern with making the change directly in web78.conf is that other Website changes that are made via the GUI will overwrite your custom change. Another approach is to set an environment variable in the web-server configuration. It is possible to control this value on a per-vhost basis, as you can place this directive in the "nginx Directives" field on the same page. For example, in NGINX: Code: fastcgi_param APP_ENV 'staging'; You should then be able to acquire this value with PHP's built-in function, e.g., getenv('APP_ENV'). Certainly less elegant, but it does work.
ok exactly And Apache does it like so; Code: SetEnv APP_ENV "staging" Didn't realize that the var would be retrievable with the getenv('APP_ENV')... good enough! thanks
Glad you were able to modify the approach for Apache. I was going to get into the whole, "If you're using Apache..." bit, but figured you would be able to adapt accordingly. Very nice. I asked a similar question shortly before you posted this one. A few weeks ago, I went through the same thing that you did today (which is why I was able to answer definitively). But one thing that I never had to try until today is expanding the approach to work with global environment variables that are propagated server-wide. I wanted to be able to define the values in PHP (not NGINX or Apache). It looks like it may not be possible (at least not without leveraging ISPConfig's config templating sytem). You may be interested in this thread, because invariably, you're going to want to do the same type of thing. https://www.howtoforge.com/communit...e-that-applies-to-all-pools-in-php-fpm.69718/ Don't be shy with that Like button. It's not my vanity speaking -- it has practical importance.