Passing an environment-variable into a php commandline script
Problem 1 Exporting environment variables
Your export is incorrect.
$ APP_ENV="development"
$ export APP_ENV
Notice that the $
is missing from the export statement! :P
First check getenv to make sure that export works:
<?php
echo getenv ("APP_ENV");
?>
Problem 2: Undefined index on this:
<?php
echo $_ENV["APP_ENV"];
?>
If you get a proper value from getenv
but not the superglobal $_ENV
then you may have to check your ini file.
Quoting php.org:
If your $_ENV array is mysteriously empty, but you still see the variables when calling getenv() or in your phpinfo(), check your http://us.php.net/manual/en/ini.core.php#ini.variables-order ini setting to ensure it includes "E" in the string.
Don't use $
in the export
command, it should be:
export APP_ENV
You can combine this with the assignment:
export APP_ENV="development"
With the $
, you were effectively doing:
export development