Setting environment variables for access in PHP using Apache

I have a Linux environment and I have a PHP web application that conditionally works based on environment variables using getenv in PHP. I need to know how these environment variables should be set for the application to work properly. I am not sure how to install this on Apache.

In addition, I need to be able to configure separate environment variables for each domain separately.

I ask for advice on how I can achieve this.

+94
php ubuntu environment-variables apache
Jun 05 '12 at 18:01
source share
4 answers

Something along the lines of:

 <VirtualHost hostname:80> ... SetEnv VARIABLE_NAME variable_value ... </VirtualHost> 
+148
Jun 05 '12 at 18:05
source share

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

 SetEnv KOHANA_ENV production 

It would be all you need to add to .htaccess to add an environment variable

+27
Jun 05 '12 at 18:08
source share

Incredibly, on httpd 2.2 on centos 6.4 this works.

Export env vars to /etc/sysconfig/httpd

 export mydocroot=/var/www/html 

Then just do it ...

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

Then finally ...

 service httpd restart; 
+6
Apr 14 '16 at 2:33
source share

If your server is Ubuntu and Apache version 2.4

Server Version: Apache / 2.4.29 (Ubuntu)

Then you export the variables to the "/ etc / apache2 / envvars" folder.

As in the line below, you need to add an additional line to "/ etc / apache2 / envvars" export GOROOT = / usr / local / go

0
May 14 '19 at 5:14
source share



All Articles