PHP command not found

When using the PHP statement in a procedure, the error at the bottom of the procedure window is:
PHP ERROR: sh: php: command not found

Using Terminal, I can enter

  php -v

and get the current version of PHP

What am I doing wrong?

I assume you have moved to macOS Monterey. Apple has removed PHP from Monterey, if you want to use it you will have to install it yourself.

https://developer.apple.com/forums/thread/681907

I’m not sure what the current status of Python, Ruby and Perl are, but Apple announced several years ago that they were going to remove all of these scripting language, so if they are not already removed, they will be. I think this is unfortunate but Apple doesn’t consult me on these decisions.

This Google search links to many other web pages on this topic.

https://www.google.com/search?q=macos+monterey+no+php&sxsrf=AOaemvIoRMYx9W7KB_W_jbUSpPWBZ4Iz2Q%3A1637355855816&source=hp&ei=TxGYYdWHL-605OUP9qGI6Ak&iflsig=ALs-wAMAAAAAYZgfXznTRUzzku6VyBweJ9fPj4q5_DgE&oq=macos+monterey+php&gs_lcp=Cgdnd3Mtd2l6EAEYAjIFCAAQgAQyBQgAEIAEMgYIABAWEB46BAgjECc6EQguEIAEELEDEIMBEMcBEKMCOggIABCABBCxAzoOCC4QgAQQsQMQxwEQowI6CwgAEIAEELEDEIMBOgUILhCABDoLCC4QsQMQxwEQowI6DgguELEDEIMBEMcBENEDOggILhCxAxCDAToLCC4QgAQQsQMQgwE6CAguEIAEELEDOg4ILhCABBCxAxDHARDRAzoLCAAQgAQQsQMQyQM6BQgAEJIDOgUILhCxAzoECAAQAzoICAAQsQMQgwE6BwgAELEDEAo6CggAELEDEIMBEAo6BAgAEAo6BwgAEIAEEApKBQg8EgExUABY7iFgjjpoAXAAeACAAYgBiAGvD5IBBDEwLjmYAQCgAQE&sclient=gws-wiz

Yes I am on Monterey and yes, Apple did not include it. But I have installed it successfully and that is how I can type

php -v 

in Terminal and get the response of the version installed. Thus my PATH is also set correctly. (Apache is also running fine as is MySQL.)

And now what are your thoughts?

Panorama expects PHP to be installed at:

/usr/bin/php

My guess would be that whatever tool you used to install PHP (Homebrew, perhaps?) installed it at a different location, and modified the shell configuration so that it would work with Terminal.app. Panorama doesn’t know anything about how the shell is configured, so it doesn’t work. There is no supported way to change the location that Panorama expects to find the PHP tool. That will probably need to be reconsidered now that we can’t rely on Apple to have installed the tool in a particular place. For now, you’ll either need to move the PHP tool (I think you might be able to set up an alias, but I’m not sure about that) or modify the source code for the PHP statement in Panorama.

Adding a alias is not as easy or possible as it once was. Turning off SIP is not a problem but even then, the System volume is still using a cryptographic hash to verify if it has been altered in any way. There is a workaround to boot without SSV but I think that is a stretch for this situation. Read-only file system with Signed System Volume

Is there an equivalent to the Python solution?

secretglobal pythonPrefixLineTemplate
pythonPrefixLineTemplate = 
"#!/some/where/else/python"

Or might a custom statement be more appropriate? If so, while the documentation on custom statements is a bit scarce, would it follow identically to custom functions?

Ok, good point.

Where did you get this solution? Did I post it at some point? I don’t remember. In any case, the PHP code is similar, so if the Python solution works, it should work for PHP also.

secretglobal phpPrefixLineTemplate
phpPrefixLineTemplate = "#!/some/where/else/php"

Please let me know if it does work, as that knowledge will save me some time when I work on issue #1209.

Local output

SecretGlobal phpPrefixLineTemplate
phpPrefixLineTemplate = "#!/Users/rameeti/homebrew/bin/php"

PHP |||php -v|||, output
Message output

PHP ERROR: sh: php: command not found

‘SecretGlobal’ not found…?

That would be odd in that it is being declared and then assigned a value immediately after. Check spelling?

I think maybe Craig was just wondering where you came up with “SecretGlobal” since it is not documented (it is secret after all in Jim’s private arsenal).

I guess you’ll have to wait for a revised version of Panorama to address this.

Did this get resolved?

I use macports and trying to run a phar with PHP is failing with shellscript and I’m certain it’s merely because the zsh is not interactive so it’s not loading the PATH or environment.

I want to run WP-cli and get results into database. Works like a charm in terminal but trying a shellscript gives me errors that I know are happening because my environment PATHS aren’t loaded.

EDIT: I fixed it for my case – I needed to include paths in the shellscript for BOTH – wp-cli is aliased at /opt/local/bin/wp and that’s also where php from macports lives… so using:
shellscript({/opt/local/bin/php /opt/local/bin/wp ... commands}) worked for me to get around the PATH issue…

Yes, this issue was resolved a couple of years ago.

No, but shouldn’t you be able to do whatever you want in your script? I think you should be able to set up environment variables with the export command in your script, before you invoke the rest of your script.


I’ve never heard of PHAR or WP-cli before. I did some Google searching, and I think WP-cli is an interactive tool? If so, you can’t use interactive tools with shellscript, at least not directly. There’s no way to inject input into STDIN so that WP-cli can read it. I think there is a UNIX tool that can do that, but I don’t know the name of it, how it works, or whether it is provided with macOS or would need to be installed with Mac Ports (or a similar tool).

Hmm, looking a bit more at the WP-cli documentation I’m not sure it is interactive. If not, then you should have no trouble running it.

In case anyone else is interested, here are some results I found with Google.

https://www.php.net/manual/en/intro.phar.php

https://wp-cli.org

1 Like

it has an interactive shell that can be invoked, but it’s main function is automation for wordpress. on the command line, you can retrieve meta data and content, etc as well as generate new posts, etc. In my case, I am pulling old posts and getting meta data out… I got it to work as expected (see edited post above)… now, I’m trying to figure out how to get the json response parsed into what I want…

so a query on a button I put on a form would pull the ID of a featured image for a post - the code would look like this:
shellscript({ /opt/local/bin/php /opt/local/bin/wp @bfp post meta list $«ID»$ --keys=_thumbnail_id --fields=meta_value --format=json})

so, if I ran it, I get this response (telling the script to return json in this example): [{"meta_key":"_thumbnail_id","meta_value":"4790339"}]

I don’t know how to extract the meta_value or tell panorama to see a dictionary there… ideally, I’d set a field value to the meta_value returned

Actually, it’d be nice to query several meta_keys at once and retrieve them.

Great - that’s just JSON. More specifically, it’s a JSON dictionary inside a one element JSON array.

You can turn that into a Panorama data array with the jsonimport( function.

Then you can use the getstructurevalue( function to extract various elements from the retuirned information.

let wpjson = shellscript(... your script here ...)
let wpinfo = jsonimport(wpjson)
let key = getstructurevalue(wpinfo,1,"meta_key")
let value = getstructurevalue(wpinfo,1,"meta_value")

The code above is very dependent on the exact data returned from WP-cli. It will be different depending on what script you pass to WP-cli. You’ll need different custom code depending on what you ask WP-cli to do. I would recommend that you study and become fluent with Panorama data arrays and data dictionaries. It would probably also be a good idea to study JSON (it’s very simple). For each WP-cli command you want to use, you’ll want to study the JSON produced so that you can figure out what code you’ll need. A bit of up-front study time to get fluent with arrays and dictionaries will probably pay big dividends in completing the project faster and with less frustration.

1 Like

awesome! thank you! I still think of arrays in FORTRAN77 and HyperCard… I can Applescript all day long, but this fancy JS stuff throws me for loops!

somehow, this little procedure will grow to test for empty fields (that are named the same as the meta_key in wordpress) and fetch the missing items in one script call… I just need to get the skeleton working and you got me pointed in all the right directions here! THANK YOU!

The next fun thing is that I have about seven databases with info and following a lot of conditional logic, plan to have a procedure/script that will build a post per day – eventually, I will have panorama push that calculated post back out to the wordpress site.

1 Like