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.
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:
-
Connect to the server via SSH (using credentials of the subscription user)
-
Change your working directory to WordPress installation path with
cd
command. In this example it ishttpdocs
:# 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
In order to use WP-CLI inside chrooted environment, it is required to add it using the following steps:
-
Connect to the server via SSH (using
root
(administrative) credentials) -
Add PHP handler to the chrooted shell as described in How to add programs to chrooted shell environment template in Plesk? article
-
Add MySQL/MariaDB client into chroot as described in How to chroot MySQL/MariaDB client for users in Plesk?
-
Add WP-CLI into chroot, using the
update-chroot.sh
script from articles above:
-
Add programs required for the PHP functioning to the template:
# ./update-chroot.sh --add env
-
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
-
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/
-
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
-
Apply the changes:
# ./update-chroot.sh --apply example.com
-
Add programs required for the PHP functioning to the template:
# ./update-chroot.sh --add env
-
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
-
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/
-
Apply the changes:
# ./update-chroot.sh --apply example.com
-
Navigate to Domains > example.com > Hosting & DNS menu, and enable RDP access for subscription user by checking
-
Using subscription user credetnails, connect to the server via RDP
-
Open
cmd.exe
and change the working directory to the WordPress installation directory. For example:C:\> cd C:\inetpub\vhosts\example.tld\httpdocs\
-
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)?
Comments
0 comments
Please sign in to leave a comment.