Articles in this section

How to use WP-CLI utility in Plesk WordPress Toolkit via Shell (SSH/CLI)?

DoNotDelete:docref ext: wptk Plesk Obsidian for Linux Plesk Obsidian for Windows

Question

How to use WP-CLI utility in Plesk WordPress toolkit via Shell?

Answer

Warning: WP-CLI commands are meant to be executed under subscription user. Running commands under root or Administartor accounts is strongly not recommended.

Plesk for Linux / non-chroot environment

In order to use WP-CLI via SSH, it is requited to enable Shell in Domains > example.com > Hosting & DNS > Hosting menu, as described in How to grant a Subscription or Domain user SSH/SFTP access to its home directory in Plesk? article. After that, you may do the following:

  1. Connect to the server via SSH (using credentials of the subscription user)

  2. Change your working directory to WordPress installation path with cd command. In this example it is httpdocs:

    # cd httpdocs/

    # ls
    index.php wp-activate.php wp-comments-post.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
    license.txt wp-admin wp-config-sample.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php
    readme.html wp-blog-header.php wp-config.php wp-includes wp-login.php wp-signup.php

After that, you may use wp commands. For example:

# wp plugin list
+---------+----------+-----------+---------+----------------+-------------+
| name | status | update | version | update_version | auto_update |
+---------+----------+-----------+---------+----------------+-------------+
| akismet | inactive | available | 5.3.6 | 5.3.7 | off |
| hello | inactive | none | 1.7.2 | | off |
+---------+----------+-----------+---------+----------------+-------------+

# wp cli version
WP-CLI 2.11.0

Plesk for Linux (chrooted shell):

In order to use WP-CLI inside chrooted environment, it is required to add it using the following steps:

  1. Connect to the server via SSH (using root (administrative) credentials)

  2. Add PHP handler to the chrooted shell as described in How to add programs to chrooted shell environment template in Plesk? article

  3. Add MySQL/MariaDB client into chroot as described in How to chroot MySQL/MariaDB client for users in Plesk?

  4. Add WP-CLI into chroot, using the update-chroot.sh script from articles above:

Ubuntu/Debian:
  1. Add programs required for the PHP functioning to the template:

    # ./update-chroot.sh --add env

  2. Copy executable files:

    # mkdir -p /var/www/vhosts/chroot/usr/local/bin/

    # cp /usr/local/bin/wp /var/www/vhosts/chroot/usr/local/bin/wp

  3. Copy WP-CLI Plesk module files:

    # mkdir -p /var/www/vhosts/chroot/opt/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/

    # cp -a /opt/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/. /var/www/vhosts/chroot/opt/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/

  4. Add link to the PHP executable file (using corresponding PHP version):

    # ln -s /opt/plesk/php/X.X/bin/php /var/www/vhosts/chroot/bin/php

  5. Apply the changes:

    # ./update-chroot.sh --apply example.com

RHEL/CentOS/AlmaLinux/Cloud Linux/Rocky Linux:
  1. Add programs required for the PHP functioning to the template:

    # ./update-chroot.sh --add env

  2. Copy executable files:

    # mkdir -p /var/www/vhosts/chroot/usr/local/bin/

    # cp /usr/local/bin/wp /var/www/vhosts/chroot/usr/local/bin/wp

  3. Copy WP-CLI Plesk module files:

    # mkdir -p /var/www/vhosts/chroot/usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/

    # cp -a /usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/. /var/www/vhosts/chroot/usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/

  4. Apply the changes:

    # ./update-chroot.sh --apply example.com

Plesk for Windows
  1. Navigate to Domains > example.com > Hosting & DNS menu, and enable RDP access for subscription user by checking

  2. Using subscription user credetnails, connect to the server via RDP

  3. Open cmd.exe and change the working directory to the WordPress installation directory. For example:

    C:\> cd C:\inetpub\vhosts\example.tld\httpdocs\

  4. Execute WP-CLI commands using corresponding PHP version (same version as on domain), and specifying WP-CLI module path. For example:

    C:\> C:\inetpub\vhosts\example.tld\httpdocs>"%plesk_dir%Additional\PleskPHP83\php.exe" "%plesk_dir%Additional\modules\wp-toolkit\wp-cli\wpt-wp-cli.php" plugin list
    +---------+----------+-----------+---------+----------------+-------------+
    | name | status | update | version | update_version | auto_update |
    +---------+----------+-----------+---------+----------------+-------------+
    | akismet | inactive | available | 5.3.6 | 5.3.7 | off |
    | hello | inactive | none | 1.7.2 | | off |
    +---------+----------+-----------+---------+----------------+-------------+

Additional Information

How to use WP-CLI feature in Plesk WordPress Toolkit (in GUI)?

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.