Environment variables and PHP

It turns out that you have to explicitly set the ENV vars in the php-fpm.conf

Here's an example:

[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log

[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
env[MY_ENV_VAR_1] = 'value1'
env[MY_ENV_VAR_2] = 'value2'

1. Setting environment variables automatically in php-fpm.conf

clear_env = no


2. Setting environment variables manually in php-fpm.conf

env[MY_ENV_VAR_1] = 'value1'
env[MY_ENV_VAR_2] = 'value2'


! Both methods are described in php-fpm.conf:

Clear environment in FPM workers Prevents arbitrary environment variables from reaching FPM worker processes by clearing the environment in workers before env vars specified in this pool configuration are added. Setting to "no" will make all environment variables available to PHP code via getenv(), $_ENV and $_SERVER. Default Value: yes

clear_env = no


Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from the current environment. Default Value: clean env

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp


I found solution in this github discussion .