How to Pass Environment Variables to Apache Server

I was using the AWS SDK for PHP to access my S3 bucket but before I could access the bucket I needed to set some environment variables. The documentation talks about different ways of setting the secret key and the key id and the method I chose was to put the key data in a credentials file within a .aws folder. This folder has to be placed within your home directory and then you can set environment variable to point to the home directory.

Since I was using WAMP, APACHE had hard time seeing my environment variables. I confirmed this by creating a simple php file with this content:

echo $_SERVER['HOME'];

and then executed this from command line using:

php test.php

and as I expected it produced the correct output. If I did the same within the APACHE server I got error about HOME variable not found. To fix this I added this line in httpd-vhosts.conf file under the <VirtualHost> section:

SetEnv HOME [your path here]

If you are using ssl on your localhost then you must modify a different configuration file. The file you want to edit is httpd-ssl.conf and is usually found here:


Within this file should be a section for VirtualHost and looks something like this:

<VirtualHost _default_:443>

go ahead and add your SetEnv directive here.

After restarting the server I was able to access the variable from within the APACHE server.