Exec - PHP return_val - 126

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 );
+5
source share
3 answers

You need to specify the full path to the executable file, and also make sure that your Apache user has the rights to execute it.

Apache does not work with bash and does not care about setting up your personal path.

+5
source

Try putting chmod 0777 in the executable:

chmod($file,0777);
+2
source

-, PHP exec() Linux exec(). bash script, /bin/ bash:

exec( "/bin/bash /usr/local/bin/myexecutablefile /full/path/to/someotherfile.js", $output, $retval );

exec() Linux script; bash , . /bin/ bash - , exec() Linux, , , script.

+1

All Articles