Download WP CLI for Temporary Use & Also Run Against Custom PHP Version

There are times when you log into the shell only to find out that the version of PHP cli is outdated. Most common with CPanel mass hosting, they use a newer version of PHP for web and an outdated version for the cli. Who uses cli anyway? Well the pros do.

Download WP Cli

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Test WP CLI

php wp-cli.phar --info

Make it easier to call

sudo mv wp-cli.phar wp
chmod +x wp

Remember the directory where you downloaded cli.

Add WP-CLI to the path.

export PATH=</path/to/wp-cli/directory>:$PATH

Test WP-CLI again

wp --info
Output:
OS:	Linux e43.ehosts.com 3.10.0-693.11.6.1.ELK.el6.x86_64 #1 SMP Tue Jan 23 10:30:30 MST 2018 x86_64
Shell:	/usr/local/cpanel/bin/jailshell
PHP binary:	/opt/cpanel/ea-php56/root/usr/bin/php
PHP version:	5.6.40
php.ini used:	/opt/cpanel/ea-php56/root/etc/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/home2/me/public_html/cgi-bin
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	/home2/me/public_html/wp-cli.yml
WP-CLI version:	2.0.0

Want to use a custom version of PHP with cli? Newer PHP versions are typically faster and way faster than PHP 5.6.

With phpinfo(); you can find the Configure Command options. Look for bindir. It will be something like:

bindir=/opt/cpanel/ea-php72/root/usr/bin

Set the WP_CLI_PHP environment variable to use your chosen php version.

export WP_CLI_PHP=/opt/php71/bin

If that doesn’t work, add this directory to your path and WP-CLI will use the newer PHP as long as you are in the same shell session.

export PATH=/opt/php71/bin:$PATH