Exit code 127 means "command not found", just as the error message says. https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
If php is in your PATH, then this should not happen. If you want to explicitly tell Drush which php to run, then set the DRUSH_PHP environment variable as explained in the Drush README. This should help out in the case of Drush commands such as the ones you mention before, that run a Drush subcommand in a new process.
Update:
To make things work correctly, you need to understand how bash initializes itself. For example, did you know that .bash_profile is sourced if you run ssh user@host
, but it is not sourced if you run ssh user@host pwd
? Drush uses the later form to re-launch Drush subprocesses, so if you initialize your PATH in .bash_profile, then it will be fine when you test it in the shell, but it will be broken for Drush subprocesses.
To get around this problem, you should also initializeexport your PATH in your .bashrc file, as bash will source this file for non-login shells. Be sure to initializeset up your PATH at the TOP of the file, as there is a line near the top that reads: [ -z "$PS1" ] && return
. This causes the script to exit if ssh did not create a tty (run ssh -t
to create a tty; Drush adds this flag for interactive commands only.)