1

I need my PATH environment variable to include /usr/local/bin when seen from PHP, so that I can execute binaries that are in /usr/local/bin with exec() in PHP code without writing their full path, e.g. exec("ffmpeg");

If from php I run echo getenv("PATH") it outputs: /sbin:/usr/sbin:/bin:/usr/bin

However if I log into the server as root via ssh and I write in the terminal echo $PATH I get: //sbin://bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

So the /usr/local/bin is already included when I log into the command line, but not when PHP is run.

So how do I add directories to the path environment variable in such a way that they are recognized also by PHP?

I tried to add SetEnv PATH $PATH:/usr/local/bin to /var/www/vhosts/mydomain.net/conf/vhost.conf (which contains other directives which do have effect), but it doesn't change a thing. I also tried by adding that to a .htaccess file (dunnow if it made sense) but it didn't work either.

I already searched the forum and found a lot of similar or identical questions but no answer, or at least none that works.

3 Answers 3

1

In your apache startup script, try to export your custom path.

IIRC, Apache defaults to common envvars when started. So, even changing its value in user's env won't do the trick.

2
  • What is the apache startup script that I have to edit?
    – matteo
    Jun 7, 2011 at 9:23
  • /etc/rc.d/init.d/httpd is default startup script for Apache on CentOS
    – AlexD
    Jun 7, 2011 at 15:38
0

edit the php.ini the clause include_path indicate in which path php take the script.

1
  • I think include_path is for php files to be included with the include() and require() directives, I don't think that has any relation with the environment variable PATH, or has it?
    – matteo
    Jun 4, 2011 at 15:15
0

Well, depending on your needs you can either set it in the script (Documenation Link)

<?php
 // Works as of PHP 4.3.0
set_include_path('/inc');

// Works in all PHP versions
ini_set('include_path', '/inc');
?>

or you can set it in the php.ini file itself (Documentation Link)

include_path=".:/php/includes
1
  • I may be wrong but I don't think that has anything to do with my question which was about the PATH environment variable for executing binaries with exec()... or will the include_path directive also work for exec()??
    – matteo
    Jun 4, 2011 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.