Expose environment variables to Apache and PHP
<h1>Background</h1>

<p>I'm trying to use <a href="http://wercker.com/" rel="noreferrer">Wercker</a> to run my test for a PHP application. Wercker uses Docker containers to setup a test environment to execute tests in. It uses Environment Variables to expose the connection params for any connected services like MySQL and Elasticsearch. Example MYSQL_PORT_3306_TCP_ADDR = 127.0.1.1</p>

<p>My core Docker containers is running Ubuntu 14.04 with PHP and Apache already installed on the container.</p>

<h1>Problem</h1>

<p>I can't seem to access the Environment Variables via php $_SERVER or $_ENV when running via Apache. It works fine if I run the script via CLI <code>php ./db_connect.php</code> or if I run PHP using its build in server <code>php -S localhost:8000</code>. However If I try and access a page via the Apache virtual host, the Environment Variables are not available.</p>

<h1>Progress</h1>

<p>I have setup Apache with the mod used to allow environmental variables "I think"</p>

<pre><code>sudo a2enmod env
sudo service apache2 restart
</code></pre>

<p>I'm trying to access the Environment Variables in my script.</p>

<pre><code>$database_host      = $_SERVER["MYSQL_PORT_3306_TCP_ADDR"];
$database_username  = $_SERVER["MYSQL_ENV_MYSQL_USER"];
$database_password  = $_SERVER["MYSQL_ENV_MYSQL_PASSWORD"];
$database_name      = $_SERVER["MYSQL_ENV_MYSQL_DATABASE"];
$elasticsearch_host = $_SERVER["ELASTICSEARCH_PORT_9300_TCP_ADDR"];
</code></pre>

<p>I can add new variables in my .htaccess, I just don't get all the system environmental variables. </p>

<pre><code>SetEnv TEST_VAR test
</code></pre>

<p>I have read this question <a href="https://stackoverflow.com/questions/13568191/how-to-get-system-environment-variables-into-php-while-running-cli-apache2hand">How to get system environment variables into PHP while running CLI &amp; Apache2Handler?</a> but i'm not sure what its suggesting to do.</p>

<h1>Question</h1>

<p>How do I expose System Environment Variables to Apache and PHP?</p>