Possible Duplicate:
Why is my $_ENV empty?
I am trying to use $_ENV in my script, but it's returning an empty array. Code is:
print_r($_ENV);
and here's what I get back:
Array ( )
The script is running on a Linux server (I have admin privileges, but I did not set up the server myself). Whether I'm logged in as admin, or regular user, if I type env from a terminal, I see about 20 separate items, so the environment is not empty.
I've used $_ENV in the past without any problems (but it's been a while). What am I missing?
Solution:
Modifications to php.ini did not do the trick. What worked is the following:
Locate your httpd config file, or your virtual host config file (in some cases, they are the same file), and add the following to it (inside the VirtualHost section), for each environment variable:
SetEnv MY_ENV_VAR_1 test1
SetEnv MY_ENV_VAR_2 test2
restart Apache.
In your php script, you use:
getenv('MY_ENV_VAR1')
to access these environment settings. SetEnv will set these variables and pass them back to Apache for use. If you want to use an existing shell environment variable, then you should add the following to your Apache config file, or your Virtual Host file:
PassEnv env_variable [env_variable]....
To make it available to Apache and your scripts.