title: How does Laravel parse the .env file?
body: <p>I would like to mimic the way a Laravel application has it's environment variables set via a <code>.env</code> file. </p>
  
  <pre><code>APP_ENV=local
  DB_DATABASE=fruits
  DB_USERNAME=fruituser
  DB_PASSWORD=secretpassword
  </code></pre>
  
  <p>So it can then set default fallbacks in <code>config.php</code> like this:</p>
  
  <pre><code>return [
      'env' =&gt; env('APP_ENV', 'production'),
  ];
  </code></pre>
  
  <p>However I am having trouble digging through the framework code to find the bit where it parses the text in <code>.env</code> and turns it into proper PHP variables. </p>
  
  <p>I have found the definition of the <code>env()</code> helper function in <code>vendor\laravel\framework\src\Illuminate\Foundation\helpers.php</code>:</p>
  
  <pre><code>function env($key, $default = null)
  {
      $value = getenv($key);
  
      if ($value === false) {
          return value($default);
  
      }
  ...
  </code></pre>
  
  <p>...but that calls another global helper function called <code>getenv()</code> and that is where the trail goes cold. </p>
  
  <p>I suspect we might be down to Symfony level now but alas I cannot find the definition of <code>getenv()</code> and your help and guidance would be greatly appreciated. </p>