Question

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

Was it helpful?

Solution 2

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

OTHER TIPS

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'].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top