14

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?

mtmacdonald
  • 14,216
  • 19
  • 63
  • 99

1 Answers1

11

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.

RaggaMuffin-420
  • 1,762
  • 1
  • 10
  • 14
  • 1
    thanks, makes sense and this works. In my case on Ubuntu, I set this in the appropriate Apache config file in /etc/apache2/sites-available. Like so: http://stackoverflow.com/questions/10902433/ – mtmacdonald May 28 '14 at 15:10