I try to execute the shell command exec in a PHP script, but exec returns 126 code, which means: โThe called command cannot be executedโ (permission problem or the command is not executable). But the funny thing is that if I run the same PHP script under cli, it works well. What is wrong with him?
Perhaps there are environmental problems? Because when I run it under Apache, it returns 127 code if I do not use the absolute path to the executable file (in cli it works well and returns 0, even if I use only the file name). The file is stored in / usr / local / bin.
UPDATE:
As pointed out in a comment, I am showing an example of my code, but there is nothing special.
This part works fine under cli, but does not work under apache (it $retvalwill be 127):
$output = array();
$retval = 0;
exec( "myexecutablefile /full/path/to/someotherfile.js", $output, $retval );
echo implode( PHP_EOL, $output );
This piece of code will return $retval = 126
$output = array();
$retval = 0;
exec( "/usr/local/bin/myexecutablefile /full/path/to/someotherfile.js", $output, $retval );
echo implode( PHP_EOL, $output );
source
share