PHP execution via passthru(), exec(), shell_exec(), …: sh: /php: No such file or directory

If you’re running PHP scripts through the command line (crontab or via a bash shell), you can get the following output:

localuser@host ~# php myscript.php
...
sh: /php: No such file or directory
...

That mostly happens when you have code like this active.

passthru("php other.php");
exec("php other.php");
shell_exec("php other.php");
...

First thing to check would be if “php” is a registered binary. Run the following as the user that is running your PHP script (hopefully not the root user).

localuser@host ~# which php
/usr/bin/php

If you get no response, try to add the full path to the PHP binary into your script.

passthru("/usr/local/php other.php");
exec("/usr/local/php other.php");
shell_exec("/usr/local/php other.php");

If you do get a response, doublecheck if safe_mode is On for the script you are running. With safe_mode on, it will block the execution of other scripts via the passthru() or exec() calls.