WP-CLI only works correctly from the command line, using the 'cli' PHP SAPI.
I am with almalinux. Whenever I run any wp cli command, I get following error
and when I run
, I get
Do I need to reinstall different version of php? How can I fix this error and make wp cli work again? Can I fix it via EasyApache 4?
WP-CLI only works correctly from the command line, using the 'cli' PHP SAPI.
You're currently executing the WP-CLI binary via the 'cgi-fcgi' PHP SAPI.
In case you were trying to run this file with a web browser, know that this cannot technically work.
When running the WP-CLI binary on the command line, you can ensure you're using the right PHP SAPIby checking that `php -v` has the word 'cli' in the first line of output.
and when I run
php -v
, I get
PHP 7.4.33 (cgi-fcgi) (built: Oct 25 2023 14:06:26)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
Do I need to reinstall different version of php? How can I fix this error and make wp cli work again? Can I fix it via EasyApache 4?
-
Hey there! The output from the error is correct as detailed here: Once that is done, I would expect the command to work normally. 0 -
Hi @cPRex, I have changed the php handlers to 'none' but I am still getting the same error. 0 -
I wouldn't expect "none" to work well as then no PHP will be processed. Could you try using a different handler? 0 -
I wouldn't expect "none" to work well as then no PHP will be processed. Could you try using a different handler?
Sorry for late reply. I only have "none" and "cgi". How can I add more?0 -
Hi @cPRex, Thank you for your reply. Turns out root user's php was in '/bin/php' and thus php -v
is returningPHP 8.2.11 (cgi-fcgi)
. WP-CLI will only works withPHP 8.2.11 (cli)
version. I tried exporting the the pathexport PATH=/usr/local/bin:$PATH
and it works but the path is not persisting. It won't work again when I close the terminal or restart the server. I am using zsh, how can I make the exported path to persist?0 -
You'd have to edit the bashrc file to change the PATH variable. Once you do that, it will be added to each new session for that user. Root has this in /root/.bashrc 0 -
Root user's php is now '/usr/local/bin/php'. But the problem is I am using 'almalinux' sudoer and with 'sudo' prefix, it is still using '/bin/php'. Now, as a workaround, I have enabled root login w/o password and with 'su' prefix into user's account from root user, I can now use the wp cli in each user's account. See the screenshot for more info. Should there be any fix, please let me know. Otherwise, I am ok with root login without password. 0 -
Root user's php is now '/usr/local/bin/php'. But the problem is I am using 'almalinux' sudoer and with 'sudo' prefix, it is still using '/bin/php'. ...
Have you tried to use "sudo -i" ?0 -
Have you tried to use "sudo -i" ?
Still returns '/bin/php'0 -
Hello,
The same here. I'm using CloudLinux 8.9 and when I try to execute
sudo -u iclanuy -i -- /usr/local/bin/wp updraftplus backup --label="Backup before update from cli" --include-files="plugins, themes"
I get that error:
Content-type: text/html; charset=UTF-8
WP-CLI only works correctly from the command line, using the 'cli' PHP SAPI.
You're currently executing the WP-CLI binary via the 'cgi-fcgi' PHP SAPI.
In case you were trying to run this file with a web browser, know that this cannot technically work.
When running the WP-CLI binary on the command line, you can ensure you're using the right PHP SAPIby checking that `php -v` has the word 'cli' in the first line of output.If I change to that user, then I can do it.
su iclanuy
[iclanuy@server2 public_html]$ wp updraftplus backup --label="Backup before update from cli" --include-files="plugins, themes"
Success: Backup has been started successfully. You can see the last log message by running the following command: "wp updraftplus backup_progress 370a7a1e9b46"
Success: Recently started backup job id: 370a7a1e9b46How can I execute wp cli commands using sudo -u user?
Thank you!
Mauricio
0 -
As far as I know, there isn't a way to do that - it expects all the commands to be run as the cPanel user. You do need to configure it as root, and then operate it as the cPanel user:
https://cpanel.net/blog/tips-and-tricks/wp-cli-install-and-manage-wordpress-on-the-command-line/
1 -
Thank you, cPRex
0 -
Sure thing!
0
Please sign in to leave a comment.
Comments
14 comments