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?
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.
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.
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.
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.