Plesk Admin: How to Install WP CLI globally on a Plesk server

Plesk, the globally recognised control panel, popular with many people who host a bunch of different WordPress websites out of the box doesn’t provide WP CLI to use if you login as root, or another user into the server. This means when users expect WP CLI to “just work” they may end up needing to use a clunky workaround which involves knowing the specific WordPress installation ID etc.

However, if you have access to the root user on the server, or a way to install things into your server, there is a way you can easily correct this issue.

Downloading WP CLI

Following the official installation guide for the first step, you can download the wp-cli bundle as follows:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Code language: JavaScript (javascript)

However, the second step of running PHP will typically fail as the PHP binaries are managed by Plesk (allowing subscriptions to run on different PHP versions and configurations), so in order to do so you will need to find where the appropiate PHP binary is for your system.

Typically these are installed into /opt/plesk/php/VERSION/bin/php where VERSION is the actual version of PHP such as 7.3, 7.4 etc. At the time of writing 7.4 is the most correct, so we go ahead and use that version. Make sure to list the directory (ls /opt/plesk/php) and see what versions you have available.

You will need to move this file into place which we differ from the official instructions. We do this because we need to make a wrapper script to call the correct version of PHP. This can be done like so:

mv wp-cli.phar /usr/local/bin/wp-cli.phar

Now in order to get your system to actually use the correct version of PHP from plesk, we need to make a wrapper script which will passthru everything correctly.

Wrapper Script

If you’re not comfortable with editing files on the command line, the first time you do this may require an additional step. In most cases you can use nano which is a simple text editor that works over the terminal. Expert users can swap the command for any other editor they feel like using:

nano /usr/local/bin/wp

If you get an error saying nano is not available, you will need to install it. This is outside the scope of this guide but a search for “how to install nano on ubuntu” or other linux distro should bring up correct instructions.

This file needs the following contents (changing 7.4 to whatever version you want to use):

#!/usr/bin/env sh /opt/plesk/php/7.4/bin/php /usr/local/bin/wp-cli.phar $@
Code language: JavaScript (javascript)

If you are new to nano, pressing ctrl+o will bring up a box asking you to confirm the filename. Pressing enter will save the file, and then ctrl+x to close the tool.

Final step before we can test if it all works is by adding executable status to our script. This tells your server this file is safe to execute:

chmod +x /usr/local/bin/wp

Now you can test this by simply calling the info command

wp --info

Conclusion

Following this guide your server should now have WP CLI installed on your Plesk linux server with root access. Note that all of the instructions are correct at the time of writing (April 2021) and could change. This is provided with no warranty and for information purposes only.


Share: Twitter icon LinkedIn icon Facebook icon

Joe

I like pushing buttons to make seamless, almost invisible experiences for people. It's a little abstract of a vision, but it's entirely possible.