title: Can't get PHP environment variables to work locally - Ubuntu 16.04
body: <p>After doing a thorough review of all the documentation, StackOverflow questions, and blog posts I can on this specific thing... together with a couple hours of troubleshooting, I still cannot find out how to get basic environment variables usage to work in my Slim PHP project.</p>
  
  <p>This is my first PHP web application project and certainly my first time getting environment variables to work in PHP.</p>
  
  <p>Basically what I'm trying to do is set a password as environment variable in a local <code>.htaccess</code> file so that password isn't exposed insecurely in the code I'm pushing to GitHub (<strong><em>.htaccess is set to be ignored on my project by git</em></strong>). </p>
  
  <p>I'd basically like to have the following code work:</p>
  
  <p><code>.htaccess</code> file:</p>
  
  <pre><code>SetEnv PASSWORD superSecretPassw0rd
  </code></pre>
  
  <p>And later on in the appropriate place(s) in my project's PHP files retrieve that variable and use it in sending emails via SMTP.</p>
  
  <p>For example in <code>/app/routes.php</code>:</p>
  
  <pre><code>$mail-&gt;Password = getenv("PASSWORD"); 
  </code></pre>
  
  <p>Right now, I am doing the first part, setting the environment variable in the <code>.htaccess</code> file. In fact, I've tried setting the Environment Variable in each of the following ways:</p>
  
  <pre><code>SetEnv HTTP_PASSWORD NeTzj6gKJp5q
  
  SetEnv PASSWORD glop
  
  RewriteRule .* - [E=TEST:PasswordJOKES10]
  </code></pre>
  
  <p>Yet when I <code>var_dump(getenv("TEST"));</code> the variable shows up as <code>bool(false)</code>.</p>
  
  <p>It's possible my <code>.htaccess</code> file isn't being read at all. When I delete the contents of the <code>.htaccess</code> file everything basically runs the same, which it also does if the file is just filled with long random lines of text. </p>
  
  <p>I've also made sure that <code>module rewrite is enabled</code>. So that's not the issue.</p>
  
  <p>I've also checked over the settings for <code>/etc/apache2/apache2.conf</code>. The most important settings look like I have them set right:</p>
  
  <pre><code>&lt;Directory /var/www/&gt;
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
  &lt;/Directory&gt;
  
  # AccessFileName: The name of the file to look for in each directory
  # for additional configuration directives.  See also the AllowOverride
  # directive.
  AccessFileName .htaccess
  </code></pre>
  
  <p><code>AllowOverride All</code> is set which supposedly makes it so <code>.htaccess</code> files can work, and the <code>AccessFileName</code> is set to <code>.htaccess</code>.</p>
  
  <p>The full path of my project is <code>/var/www/html/east-end-php-site/</code> with directory structure basically like this:</p>
  
  <pre><code>/east-end-php-site/
    |-----&gt; /app/
    |-----&gt; /config/
    |-----&gt; /vendor/
   composer.json
   README.md
   .htaccess
   index.php
  </code></pre>
  
  <p>My local setup:</p>
  
  <ul>
  <li>Ubuntu -v 16.04</li>
  <li>Apache2 -v 2.4.18</li>
  <li>PHP -v 7.0.22</li>
  </ul>
  
  <p>Project is run by running command <code>php -S localhost:8000</code> in the terminal from the root of that directory.</p>
  
  <p>I've currently hit a wall on this one. Please tell me StackOverflow comrades, what am I doing wrong? Where should I take my troubleshooting next? What might fix this? </p>
  
  <p><strong>Extra Reference 1</strong></p>
  
  <p>The whole <code>.htaccess</code> file looks like this:</p>
  
  <pre><code>AllowOverride ALL
  
  RewriteEngine On
  
  SetEnv HTTP_TEST NeTzj6gKJp5q
  
  SetEnv TEST glop
  
  
  # Some hosts may require you to use the `RewriteBase` directive.
  # If you need to use the `RewriteBase` directive, it should be the
  # absolute physical path to the directory that contains this htaccess file.
  
  RewriteBase /var/www/html/east-end-php-site/
  
  RewriteCond %{REQUEST_FILENAME} -s [OR]
  RewriteCond %{REQUEST_FILENAME} -l [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [NC,L]
  
  
  RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
  RewriteRule ^(.*) - [E=BASE:%1]
  RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
  
  RewriteRule .* - [E=TEST:PasswordJOKES10]
  </code></pre>