Skip to main content

WP-CLI only works correctly from the command line, using the 'cli' PHP SAPI.

Comments

14 comments

  • cPRex Jurassic Moderator
    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
  • Optimizr
    Hi @cPRex, I have changed the php handlers to 'none' but I am still getting the same error.
    0
  • cPRex Jurassic Moderator
    I wouldn't expect "none" to work well as then no PHP will be processed. Could you try using a different handler?
    0
  • Optimizr
    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
  • cPRex Jurassic Moderator
    Ah, I assumed there were more options installed on your system. You can add other handlers through EasyApache with these steps:
    0
  • Optimizr
    Hi @cPRex, Thank you for your reply. Turns out root user's php was in '/bin/php' and thus php -v
    is returning PHP 8.2.11 (cgi-fcgi)
    . WP-CLI will only works with PHP 8.2.11 (cli)
    version. I tried exporting the the path export 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
  • cPRex Jurassic Moderator
    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
  • Optimizr
    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
  • quietFinn
    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
  • Optimizr
    Have you tried to use "sudo -i" ?

    Still returns '/bin/php'
    0
  • ProNet Tecnologia

    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: 370a7a1e9b46

    How can I execute wp cli commands using sudo -u user?

    Thank you!

    Mauricio

    0
  • cPRex Jurassic Moderator

    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
  • ProNet Tecnologia

    Thank you, cPRex

    0
  • cPRex Jurassic Moderator

    Sure thing!

    0

Please sign in to leave a comment.