Home > Back-end >  PHP shell script in Automator MacOS Monterey no longer works
PHP shell script in Automator MacOS Monterey no longer works

Time:04-22

MacOS Monterey no only seems to support PHP within Automator.

You can run PHP from the Terminal without error (if installed via Brew) but running PHP scripts from Automator in a "Run Shell Script" gives the error

php: command not found

In the Terminal, running

which php

Results in /usr/local/bin/php.

Interestingly the newer Shortcuts app supports PHP scripts. Any ideas how to get Automator working with PHP again?

CodePudding user response:

This happened because your path to PHP is in /user/local/bin and that it is not part of the PATH used by Automator anymore, as it seems.

In an unmodified Automator "Run Shell Script" step, the PATH variable contains

/usr/bin:/bin:/usr/sbin:/sbin

So, the simple way to fix it is to add /usr/local/bin to the PATH in your "Run Shell Script".
In order to do that, you juste have to add a first line in the said task that would consist of:

PATH="/usr/local/bin:$PATH"

From there on, Automator will be able to find the PHP binary correctly, as it was before.


More information on what is the PATH variable and what it does mean in Linux and Unix (Mac OS is a Unix-like distribution) can be found here.

  • Related