问题描述
在centos和Redhat上,我创建了一个文件/etc/profile.d/marketing_vars.sh并在其中添加了以下行。
On centos and Redhat I created a file /etc/profile.d/marketing_vars.sh and added following lines to it
#Vars for PowerMail
export CmsRoot="/var/www/html/cms/"
export PMRoot_Dev="/var/www/html/powermail/"
export PMRoot_QA="/var/www/html/powermail/"
export PMRoot_Pro="/var/www/html/powermail/"
在命令行中,我打source marketing_vars.sh
和chmod + x /etc/profile.d/marketing_vars.sh
On command line i hit "source marketing_vars.sh"and "chmod +x /etc/profile.d/marketing_vars.sh"
我创建了一个test.php文件并添加了这些行到它
I then created a test.php file and added these lines to it
error_reporting(E_ALL ^ E_NOTICE);
echo "PMRoot_Dev = " . getenv("PMRoot_Dev");
echo "<br>";
echo "PMRoot_QA = " . getenv("PMRoot_QA");
echo "<br>";
echo "PMRoot_Pro = " . getenv("PMRoot_Pro");
echo "<br>";
当我浏览一个test.php时,我没有任何变量的值。任何人都可以帮助?
When I browse a test.php I get no value for any of the variable. Can anyone help ?
推荐答案
Apache on Centos不包括您期望的env变量。一个解决方案是手动将文件包含在/ etc / sysconfig / httpd中。
Apache on Centos doesn't include the env variables like you expect. One solution is to include by hand the file inside /etc/sysconfig/httpd.
- append /etc/profile.d/marketing_vars.sh到/ etc / sysconfig / httpd的结尾
- 重新启动apache
在apache中一致,CLI和crons是使用一个配置文件,并包含/解析它来获取变量。
The best solution to be consistent in apache, CLI and crons is to use a configuration file and include/parse it to get the variable.
这篇关于使用PHP获取用户环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!