Skip to content
Advertisement

How to get PHP to be able to read system environment variables

I am using PHP as PHP-FPM on Centos. I am trying to follow the http://12factor.net/ guidelines of having the settings be stored in environment variables.

I have created a file in /etc/profile.d that sets the environment variables I want, and the environment variables appear when tested in the CLI via Bash i.e. running the bash script:

JavaScript

shows the correct output.

I have set the clear_env setting to false and variables_order to EGPCS, however, the variable I have set does not show up in PHP either getenv('SOME_SERVER_SETTING') or doing var_dump($_ENV)

What other setting needs to be set to allow PHP-FPM to receive all of the server environment variables, and in particular those set through a shell script in /etc/profiles.d on Centos?

Advertisement

Answer

Security reasons 🙂

See /etc/php5/fpm/pool.d/www.conf (debian location, may be different on CentOs)

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement