4

When I'm trying to execute a PHP script using shell_exec(), it's not working.

In the error_log file it shows:

PHP Warning: shell_exec() [function.shell-exec]: Unable to execute 'php /home/snabbsam/public_html/.....

System
Centos

shell_exec works with clamscan
shell_exec() works on clamscan() function of clamav.
But it's not executing PHP script

Things I've checked:

Community
  • 1
  • 1
Anish
  • 1,164
  • 4
  • 15
  • 27
  • 3
    Have you tried adding a full path to the php executable? I doubt it'll make a difference, but it certainly can't hurt. – andrewsi Jul 13 '12 at 13:46
  • intitially i used $seoutput = shell_exec('php /home/...'); After your suggestion, I used $seoutput = shell_exec('/usr/local/lib/php /home/s..'); Now there's no entry in error_log, $seoutput is blank & there's no output. Also the target script is not getting executed – Anish Jul 13 '12 at 13:54
  • 1
    No, I meant adding the path to where `php` can be found. – andrewsi Jul 13 '12 at 13:56
  • php.ini is present in "/usr/local/lib/php.ini". So I gave the path to PHP as "/usr/local/lib/php". Isn't this the way? – Anish Jul 13 '12 at 14:02
  • 2
    You'll need to find the php executable, not the config file – andrewsi Jul 13 '12 at 14:04
  • wow. thanks bro. the php file was actually at "/usr/local/bin". When i used $seoutput = shell_exec('/usr/local/bin/php /home/s..'); it worked. thanks a lot bro. Please put this as an answer. I'll mark it – Anish Jul 13 '12 at 14:17
  • 1
    Huh. You'd've thought that PHP would know where its own executable was. The mysteries of file permissions and environment variables are clearly too complex for me before my second coffee of the day. – andrewsi Jul 13 '12 at 14:23

1 Answers1

5

Try adding a full path to where the executable for php is in your shell_exec call, just in case it's in a directory that's not accessible by default for the webserver user.

andrewsi
  • 10,807
  • 132
  • 35
  • 51
  • 2
    To get path to the php executable use "which php" command as mentioned in http://serverfault.com/a/58388 – Anish Jul 13 '12 at 14:31