Can't get Environmental variables into PHP Script

2.6k views Asked by At

I have environmental variables set in /etc/bash.bashrc and profile. They work fine in shell scripts, but not php.

I have tried:

$VAR = getenv('VAR');
$VAR = $_ENV["VAR"];

If I run the php script from the command line, they print out ok. But if I run it from web, they remain blank.

I did some research and edited php.ini to have an "E" in the variables order. Also commented out the next line about request_order (since it says leaving blank will default back to value set in variables_order). I restarted and it didn't work.

Solved (partially): I added "SetEnv VAR /dir/dir/dir" to the /etc/apache2/sites-available/default file. However, I still have the problem of stringing together the $VAR and the rest of the dir...that's not working. For example:

$VAR = "/var/www";
$new = "$VAR/dir2/file.txt";

When I go to open the file $new, the php script just hangs (when run from web browser). However, if I run the php script from the command line, the dang thing works! Twilight zone.

0

There are 0 answers