I'm trying to use a custom environment variable for environment detection in my PHP application. I've set the variable system-wide in /etc/environment, rebooted, and checked that it is visible through the terminal using printenv.
I've also checked that it is visible when running PHP at the command line:
php -r 'echo getenv("LOCAL_DEVELOPMENT");'
//returns 'true' as expected
But when I try from a web page script, the variable is not found:
var_dump(getenv("LOCAL_DEVELOPMENT"));
//returns 'boolean false' (not expected)
I'm using Ubuntu 12.04 LTS with PHP 5.4 and Apache 2.2.
Why is the variable not visible from a web script, and how do I fix this?
Assuming your using apache server, I think its down to Apache being restricted from the System Environment variables.. for security.
You should set env variables on apache like SetEnv LOCAL_DEVELOPMENT true
or even better SetEnv APPLICATION_ENV development
is generally considered the standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With