简体   繁体   English

如何设置环境变量供PHP在centos中访问?

[英]How to set up environment variable for PHP to access in centos?

I need to set an environment variable in a way that a PHP script is able to access it 我需要以一种PHP脚本能够访问它的方式设置环境变量

my system is Centos 6, 64 bits , with Apache server and PHP 我的系统是Centos 6,64位 ,带有Apache服务器和PHP

Basically I'm using a third party linux library that uses xulrunner. 基本上,我正在使用使用xulrunner的第三方linux库。 Xulrunner is installed on a folder in the centos server. Xulrunner安装在centos服务器的文件夹中。

I need to set an environment variable to indicate this tool where xulrunner is installed. 我需要设置一个环境变量来指示此工具在xulrunner的安装位置。

When i set that environment variable using 当我使用设置该环境变量时

 Export Variable=location

In the ssh command line, it works great, perfect, and the tool executes perfect ssh命令行中,它运行良好,完美,并且工具执行完美

but when I try from php it fails because its not finding the location, because obviously its not accessing that environment variable 但是当我从php尝试时,它失败了,因为找不到位置,因为显然没有访问该环境变量

so I need help to set an environment variable in a way that PHP script and user apache can access it 所以我需要帮助来设置环境变量,以便PHP脚本和用户apache可以访问它

thank you 谢谢

Make sure you have mod_env enabled for Apache. 确保已为Apache启用mod_env Then, in your Apache configuration file, you can add this line at an appropriate location: 然后,在您的Apache配置文件中,您可以在适当的位置添加以下行:

SetEnv VARIABLE=Location 

You can then access it via $_SERVER['VARIABLE'] . 然后,您可以通过$_SERVER['VARIABLE']

I think your problem is that the environment variable is not defined when you executes the script, try this: 我认为您的问题是执行脚本时未定义环境变量,请尝试以下操作:

1.- Edit your .bash_profile and add this line (put xulrunner directory if you want): 1.-编辑您的.bash_profile并添加以下行(如果需要,输入xulrunner目录):

export PATH_XUL=/tmp

2.- Reload console 3.- Executes this php (it should write /tmp ) 2.-重新加载控制台3.-执行此php(应该写为/tmp

<?
  echo getenv("PATH_XUL");
?>

This environment variable is declared for your user, to declare variable to all users you can add the export directive to /etc/profile.d/xul.sh 该环境变量是为您的用户声明的,要向所有用户声明该变量,可以将export指令添加到/etc/profile.d/xul.sh

If i don't understand your problem correctly, let me know 如果我不能正确理解您的问题,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM