My system is Ubuntu and I have set my environment variables in /etc/environment
.
If I\'m running PHP script using
On ubuntu, PHP uses different ini files for regular and CLI processes.
There should be few ini files like /etc/php5/cli/php.ini
, /etc/php5/fpm/php.ini
or /etc/php5/php.ini
. Open related INI file and change the
variables_order = "GPCS"
line to
variables_order = "EGPCS"
.
After that, you would get the environment variables which you set before using $_ENV['varname'].
From php.ini about variables_order
:
Abbreviations for the following respective super globals: GET, POST, COOKIE,
ENV and SERVER. There is a performance penalty paid for the registration of
these arrays and because ENV is not as commonly used as the others, ENV is
is not recommended on productions servers. You can still get access to
the environment variables through getenv() should you need to.
So you can try to use getenv() instead of $_ENV[].