Using WP-CLI on SiteGround cPanel Account

I recently moved my main site to SiteGround, which has been pretty nice so far. One of the little issues I’ve had has been the same as several other hosts: not using the latest version of WP-CLI on shared hosting accounts. It’s not unusual, and often not a major problem, but I recently came across an issue that prevents me from using the version installed on the server (0.18.0) with the version of WordPress I’m running on the site (4.4 trunk). Every time I tried to use certain wp commands, I was greeted with a fun new error message:

Fatal error: Cannot redeclare class WP_Http in /home/morganes/public_html/wp-includes/class-http.php on line 21

WordPress 4.4 is undergoing some massive file changes, specifically with separating classes, functions, and implementation code into their own files and using the original file to load them all for backwards compatibility. One of those changes caused an error with WP-CLI trying to redeclare WP_Http the class when it loaded it via require instead of require_once. That’s been fixed in 0.20.0, so I asked my host to upgrade to it.

Since I have shared hosting, an upgrade to the script would involve upgrading it for all users. That’s something that’s done on a schedule, and I don’t know when that’ll happen. SiteGround’s systems engineering team hasn’t upgraded yet, so they suggested installing a local version of wp-cli on my account and using it. I followed the Alternative Install Methods guide but kept running into a problem with the output and strange characters. After much trial-and-error, I found out that the shared WP-CLI script uses a different version of PHP than the regular command line does. Making a couple of changes to my .bash_profile finally got the latest version working.

Here’s the final version that’s working for me with WP-CLI v0.20.1 and WordPress 4.4-alpha. I’ve decided to use wpcli as my command for testing, so I can keep SiteGround’s version of wp to know when they’ve updated.

# WP-CLI from user account
export WP_CLI_PHP="/usr/local/php54/bin/php-cli"
alias wpcli="$WP_CLI_PHP $HOME/.wp-cli/wp-cli.phar --path=$HOME/public_html/"

Leave a Reply