Link to home
Start Free TrialLog in
Avatar of goodatunix
goodatunix

asked on

PHP Path for System() Command running in Apache

I am trying to run a system() command but it is failing because it doesn't know where to find the command.  If I run system("echo $PATH") it responds back "/usr/sbin:/usr/bin".  When I run phpinfo() every PATH that seems pertinent responds back "/usr/sbin:/usr/bin".  I am running the script and PHP through Apache_1.3.27, how do I change the default PATH?

Answers that change the PATH for a single script will not help, I have multiple scripts pulled down from various locations on the web and would prefer not to have to visit each file for each application to make the change take affect.

--goodatunix
Avatar of us111
us111
Flag of Luxembourg image

you should specify all the time the path to the command or to the file. for instance:
system("/usr/bin/image /home/goodatunix/file.jpg");
you should specify all the time the path to the command or to the file. for instance:
system("/usr/bin/image /home/goodatunix/file.jpg");
try
$_SERVER['PATH']= "all path";

or see the putenv function
http://www.php.net/manual/en/function.putenv.php
Avatar of goodatunix
goodatunix

ASKER

Simply changing the command to include the full path will not work.  I don't want to have to visit each script.  I would prefer to find a way to change the environment variable for PATH that is passed to PHP.
Simply changing the command to include the full path will not work.  I don't want to have to visit each script.  I would prefer to find a way to change the environment variable for PATH that is passed to PHP.
I found the answer after much searching... It seems that when the service is started it takes the PATH from the environment.  I modified apachectl so that it included a "PATH=/usr/local/bin:$PATH; export PATH" statement.  Then ran phpinfo() and found that the PATH had been updated.

--goodatunix
don't forget to close the question
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial