Arcanist php command not found while updating variables_order

The following code from <arcanist>/src/utils/PhutilExecutionEnvironment.php is failing when pushing to a Git repository (it may concern other actions). The offending code is the following:

list($env) = execx(
  'php -d variables_order=E -r %s',
  'echo json_encode($_ENV);');

Failing with this error message:

$ git push --set-upstream origin main
Enumerating objects: 28, done.
Counting objects: 100% (28/28), done.
Delta compression using up to 8 threads
Compressing objects: 100% (25/25), done.
Writing objects: 100% (28/28), 17.19 KiB | 1.32 MiB/s, done.
Total 28 (delta 4), reused 0 (delta 0), pack-reused 0
remote: [2020-09-11 15:49:55] EXCEPTION: (CommandException) Command failed with error #127!
remote: COMMAND
remote: php -d variables_order=E -r 'echo json_encode($_ENV);'
remote:
remote: STDOUT
remote: (empty)
remote:
remote: STDERR
remote: sh: php: command not found
remote:  at [<arcanist>/src/future/exec/ExecFuture.php:421]
remote: arcanist(head=stable, ref.master=2e02332216c6, ref.stable=ccd39feb6d3b)
remote:   #0 ExecFuture::raiseResultError(array) called at [<arcanist>/src/future/exec/ExecFuture.php:325]
remote:   #1 ExecFuture::resolvex() called at [<arcanist>/src/future/exec/execx.php:17]
remote:   #2 execx(string, string) called at [<arcanist>/src/utils/PhutilExecutionEnvironment.php:40]
remote:   #3 PhutilExecutionEnvironment::repairMissingVariablesOrder() called at [<arcanist>/support/init/init-script.php:104]
remote:   #4 __arcanist_init_script__() called at [<arcanist>/support/init/init-script.php:115]
remote:   #5 include_once(string) called at [/opt/phacility/phabricator/scripts/init/lib.php:12]
remote:   #6 init_phabricator_script(array) called at [/opt/phacility/phabricator/scripts/init/init-script.php:9]
remote:   #7 require_once(string) called at [/opt/phacility/phabricator/scripts/__init_script__.php:3]
remote:   #8 require_once(string) called at [/opt/phacility/phabricator/scripts/repository/commit_hook.php:34]

Context

  • OS: Red Hat Enterprise Linux Server release 7.8
  • ARC: ccd39feb6d3b (25 Jul 2020)
  • Phabricator: 5fff4ed8dbb7 (5 Sep 2020)

The thing is the PHP package is a Red Hat Software Collection which install the package outside of the usual file hierarchy. My whole Phabricator instance is installed to take this fact into account.

I have for example to setup the PATH environment variable via ~/.ssh/enviroment for the user controlling SSH access to the repositories.

# cat /etc/passwd
vcs:x:995:992:Phabricator user to allow SSH connections.:/srv/vcs:/bin/sh
# cat /srv/vcs/.ssh/environment
PATH=/opt/rh/rh-php71/root/usr/bin:/opt/rh/rh-php71/root/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

The whole thing works good, however, it seems the execx statement looses the environment variables already in place an therefore cannot get to the php executable.

Workaround

Add “E” to variables_order in php.ini.