WordPress Core Contributor

Tag Archives: WP-CLI

WP-CLI is a powerful tool that can help make common WordPress maintenance tasks easier, especially if you want to automate those tasks using cronjobs in a secure way. Here at Bluehost, we love this tool, and even provide it pre-installed on every hosting account.

There are some gotchas that can confuse even developers that are already familiar with WP-CLI. So I wanted to quickly outline them.

Using the Pre-Installed Command

The official instructions for WP-CLI instruct users to install it as the super short and convenient “wp” command. However, because our shared hosting accounts support multiple versions of PHP including version 5.2, which WP-CLI does not support, we were required to provide a wrapper around this command called “wpcli”. So every time you see instructions for running a WP-CLI command, you must replace “wp” with “wpcli”. This wrapper already knows how to force WP-CLI to always use PHP 5.4 (or later). For example, here’s how to check which themes you have installed:

We rely on this tool ourselves to help provide you higher quality support, but in the interest of security, we’re required to review updates to any tools we install on our servers, so sometimes our version of WP-CLI might not be the latest version available. If you find yourself needing some newer functionality or fixes to bugs within WP-CLI, you might still want to install the latest version on your hosting account yourself…

Installing WP-CLI on your Hosting Account

Since shared hosting does not provide you with root access to the server, the recommended installation instructions provided by WP-CLI won’t work. Instead, we’re going to install WP-CLI as a “user-specific installation”. It is still perfectly possible to install WP-CLI without root access without losing any functionality provided by WP-CLI.

We are still going to download WP-CLI in the recommended way, however, we are going to download it into your ~/bin directory instead:

And rather than using the “php” command as instructed by WP-CLI, Bluehost accounts are required to explicitly use the “php-cli” command to run PHP in command line mode. So you can check that WP-CLI is working correctly by running this:

WP-CLI is actually installed now, however, it’s not very convenient to use still. You don’t want to have to run “php-cli ~/bin/wp-cli.phar” every time you want to run a WP-CLI command, so we’re going to setup an alias for it so you can just run “wp” like you normally would.

To do this, we need to edit our ~/.bashrc file, and add our alias right alongside any other aliases setup for our account. You’ll notice that Bluehost has provided a few basic ones in this file already. We’re just going to add one more, the location in the file isn’t important (but I like to organize all of my aliases in one spot next to each other). Just add the following line to this file:

alias wp='php-cli ~/bin/wp-cli.phar'

Once you save this file, we’re done. You can either log out and SSH back in for this alias to be loaded, or you can run the following command to get it working immediately: