Reputation: 3128
Ubuntu 16.04, php7.0-fpm, apache 2.4, nginx 1.10.0
I added a system-wide environment variable to both possible locations:
/etc/environment:
ENVTEST=123
/etc/profile.d/env.sh:
export ENVTEST=123
Checking:
vagrant@localhost:~$ echo $ENVTEST
123
In /etc/php/7.0/fpm/pool.d/www.conf I pass the variable to PHP:
env[ENVTEST] = $ENVTEST
But this variable value is a blank string in the $_SERVER array.
If I use a static value in www.conf env[ENVTEST] = 123
it works fine.
In console mode I can access the variable value, it doesn't work only in php-fpm mode.
I also tried to set the variable via SetEnv
in Apache config, but it gives the same result - the variable is set but the value is a blank string.
Upvotes: 2
Views: 1416
Reputation: 995
You can test the value is set correctly by using the getenv()
function within your script. I have not found a way to push environment variables safely through a script other than setenv()
, but if you would it may not push permanent changes to your runtime environment, and might only set it each time you run.
Upvotes: 1