问题
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/"
On command line i hit "source marketing_vars.sh" and "chmod +x /etc/profile.d/marketing_vars.sh"
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>";
When I browse a test.php I get no value for any of the variable. Can anyone help ?
回答1:
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 to the end of /etc/sysconfig/httpd
- restart apache
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.
来源:https://stackoverflow.com/questions/17447360/getting-user-environment-variables-using-php