Passing an environment-variable into a php commandline script
command-line-interface, environment-variables, php
Solution
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
Problem
I want to set an environment-variable, then access it in PHP, but cannot find how to do so. In the (linux) shell, I run: ``` $ APP_ENV="development" $ export $APP_ENV ``` Then I run a simple test script testenv.php: ``` <?php print $_ENV["APP_ENV"]; print getenv("APP_ENV"); ``` From the same shell where that variable was set: ``` $ php testenv.php ``` This Prints nothing and throws a notice: ``` Notice: Undefined index: APP_ENV in /xxxx/envtest.php on line 2 ``` Notice makes sense, because APP_ENV is simply not found in the environment-variables, `getenv()` throws no warning but simply returns nothing. What am I missing?