Setting environment variables for accessing in PHP when using Apache Setting environment variables for accessing in PHP when using Apache apache apache

Setting environment variables for accessing in PHP when using Apache


Something along the lines:

<VirtualHost hostname:80>   ...   SetEnv VARIABLE_NAME variable_value   ...</VirtualHost>


You can also do this in a .htaccess file assuming they are enabled on the website.

SetEnv KOHANA_ENV production

Would be all you need to add to a .htaccess to add the environment variable


Unbelievable, but on httpd 2.2 on centos 6.4 this works.

Export env vars in /etc/sysconfig/httpd

export mydocroot=/var/www/html

Then simply do this...

<VirtualHost *:80>  DocumentRoot ${mydocroot}</VirtualHost>

Then finally....

service httpd restart;