使用Apache时设置用于在PHP中访问的环境变量
I have a Linux environment and I have a PHP Web Application that conditionally runs based on environment variables using getenv
in PHP. I need to know how these environment variables need to be set for the application to work correctly. I am not sure how to set this up on Apache.
Also, I need to be able to configure separate environment variables for each domain separately.
Please advice on how can I achieve this.
我有一个Linux环境,我有一个PHP Web应用程序,它使用 此外,我需要能够分别为每个域配置单独的环境变量。 p>
请告知我如何实现这一目标。 p>
div> getenv基于环境变量有条件地运行 PHP中的 code>。 我需要知道如何设置这些环境变量以使应用程序正常工作。 我不知道如何在Apache上设置它。 p>
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;
If your server is Ubuntu and Apache version is 2.4
Server version: Apache/2.4.29 (Ubuntu)
Then you export variables in "/etc/apache2/envvars" location.
Just like this below line, you need to add an extra line in "/etc/apache2/envvars" export GOROOT=/usr/local/go