1

I need to set an environment variable in a way that a PHP script is able to access it

my system is Centos 6, 64 bits , with Apache server and PHP

Basically I'm using a third party linux library that uses xulrunner. Xulrunner is installed on a folder in the centos server.

I need to set an environment variable to indicate this tool where xulrunner is installed.

When i set that environment variable using

 Export Variable=location

In the ssh command line, it works great, perfect, and the tool executes perfect

but when I try from php it fails because its not finding the location, because obviously its not accessing that environment variable

so I need help to set an environment variable in a way that PHP script and user apache can access it

thank you

Krish R
  • 22,583
  • 7
  • 50
  • 59
  • Did you try to use `getenv()`? Check it http://us1.php.net/manual/en/function.getenv.php, and show your code – Sal00m Nov 15 '13 at 07:51

2 Answers2

2

Make sure you have mod_env enabled for Apache. Then, in your Apache configuration file, you can add this line at an appropriate location:

SetEnv VARIABLE=Location 

You can then access it via $_SERVER['VARIABLE'].

cweiske
  • 30,033
  • 14
  • 133
  • 194
Atle
  • 1,867
  • 12
  • 10
0

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):

export PATH_XUL=/tmp

2.- Reload console 3.- Executes this php (it should write /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

If i don't understand your problem correctly, let me know

Sal00m
  • 2,938
  • 3
  • 22
  • 33