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