1

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.

Community
  • 1
  • 1
EastsideDev
  • 6,257
  • 9
  • 59
  • 116
  • What is the value of `variables_order` in your `php.ini`? – Aamir Nov 09 '12 at 20:58
  • I read the stackoverflow link and changed the value of variables_order to add E to the end. It is still not working. When I print the $_ENV super global, I still don't see the env variables I set. If I also go gentenv('ENV_VAR_NAME'), I get nothing. Another other php.ini settings I should be looking at? – EastsideDev Nov 09 '12 at 22:22

0 Answers0