PHP和Apache的环境变量 [英] PHP and Apache environment variables

查看:193
本文介绍了PHP和Apache的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个环境变量在Linux中的Apache启动。

I want to pass an environment variable in linux to apache on start up.

出口MYVAR = 5
- 我定义在命令行上我的环境变量

export MYVAR=5 --I define my environment variable on the command line

PassEnv MYVAR
--set阿帕奇导入变量在Apache的配置文件

PassEnv MYVAR --set apache to import the variable in apache config file

apachectl中重启
- 当我重新启动Apache我没有得到一个错误信息。不过,我已经注意到
如果我没有创造我的第一步环境变量,我得到一个警告信息,因此必须在这里工作。

apachectl restart --when I restart apache I don't get an error message. However I have noticed that if I do not create the environment variable in my first step, I get a warning message, so must be working here

回声$ _ SERVER ['MYVAR']
--i尝试访问PHP内的环境变量,但它没有定义

echo $_SERVER['MYVAR'] --i try to access the environment variable within PHP but it is not defined

我认为,如果我尝试PassEnv已经退出环境变量(我没有带自己创建一个),它工作正常。该SETENV指令还正常工作。

I've observed that if I try to PassEnv an environment variable that already exits (one that I havn't created myself) it works fine. The SetEnv directive also works fine.

我真的想传递一个环境变量的Apache飞没有在文件中写它。帮助非常AP preciated。

I'd really like to pass an environment variable to apache on the fly without writing it in a file. Help much appreciated.

我使用CentOS的,PHP5和Apache2的。

I'm using CentOS, PHP5 and Apache2.

感谢。

更新
看来,如果我直接调用httpd的apache的启动和不使用apachectl中这是一个shell脚本环境变量被传递。我本来以为导出将导出的变量shell脚本没有?我不是一个Linux的大师如此原谅我缺乏知识。

update it seems the environment variable gets passed if i invoke the apache startup directly with httpd and not use apachectl which is a shell script. I would have thought that the "export" would have exported the variable to the shell script no? I am not a linux guru so excuse my lack of knowledge.

推荐答案

如果您想这个环境变量要传递到Apache,你应该确保所述环境变量对Apache正在运行的环境中定义。要做到即,最简单的方法是一个出口MYVAR =值行添加到envvars中(应该是位于/ etc / apache2的)或启动阿帕奇(/ etc中的脚本/ init.d中),并添加您PassEnv MYVAR它在你的Apache配置的通缉。

If you want the environment variable to be passed to apache, you should make sure that said environment variable is defined for the environment that apache is running in. To do that, the easiest option is to add an export MYVAR=value line to envvars (should be located in /etc/apache2) or the script that starts apache (in /etc/init.d), and add your PassEnv MYVAR where it's wanted in your apache configuration.

重启动Apache应该确保MYVAR环境变量传递。据我所知,而Apache是​​运行的,虽然你将不能够改变这个变量的值...

Restarting apache should make sure the MYVAR environment variable is passed. AFAIK you won't be able to change the value of this var while apache is running though...

有关CentOS的一些相关信息:<一href=\"http://php.dzone.com/news/inserting-variable-headers-apa&default=false&zid=159&browser=16&mid=0&refresh=0\">http://php.dzone.com/news/inserting-variable-headers-apa&default=false&zid=159&browser=16&mid=0&refresh=0

Some relevant info for CentOS : http://php.dzone.com/news/inserting-variable-headers-apa&default=false&zid=159&browser=16&mid=0&refresh=0

这篇关于PHP和Apache的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆