Download WP CLI Temporarily & Using With Custom PHP Versions

Download WP CLI for Temporary Use

There are times when you log into the shell only to find out that the version of PHP WP 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.

Ever Felt Stuck Finding No WP CLI Installed?

— Right When You Needed It The Most?

In the process of a WordPress Malware Cleanup, after having run a full scan and with a complete list of infections, we realized that this was a matter of quickly fixing all the malicious-files with a few WP CLI commands. WordPress core files were infected as was a huge list of infected plugins as well. Not having WP CLI meant hours of work, downloading the right version of plugins, extracting, overriding or uploading over FTP. Dang! There’s got to be a way to get this thing up and running instead of running under a site outage and downtime impacting visitors and affecting sales.

Wasn’t it possible to download WP CLI temporarily and use it?

It was. WP CLI is just another command-line tool that can be downloaded to any location, added to the path and the commands executed against any PHP version of your choice. Once you are done, delete and poof!

Applications of WP CLI

WP CLI is a command line interface for WordPress. It is efficiently used for managing a WordPress site without a web browser. There are commands to backup a site, update plugins, themes & WordPress core, search and replace WordPress database, etc. It is an effective tool for fixing a hacked WordPress site. For example, you can:

Reinstall infected WordPress Core via WP CLI

Step-by-Step guide to efficiently reinstalling infected WordPress Core using WP CLI

Reinstall infected WordPress Plugins via WP CLI

Step-by-Step guide to efficiently reinstalling infected WordPress Plugins using WP CLI

Download WP CLI

curl -O


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
OS:	Linux 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

Using Custom PHP version with WP CLI

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:


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

WP CLI Change PHP Version Temporarily

/path/to/php//version/binary /path/to/wp-cli/binary


/opt/cpanel/ea-php72/root/usr/bin/php ~/public_html/wp-cli.phar <command>

Frequently Asked Questions

What is WP CLI?

WP CLI is a command-line interface for managing WordPress sites without a web browser. It offers various commands for tasks like backing up a site, updating plugins, and more.

How can I use a custom PHP version with WP CLI?

The article provides detailed instructions on using a custom PHP version with WP CLI, including setting the WP_CLI_PHP environment variable and modifying the PATH. If you want you can pass the full path to the wp-cli.phar file to PHP and use it.

What are the risks of using an outdated PHP version?

Using an outdated PHP version can lead to compatibility issues, reduced performance, and potential security vulnerabilities. It’s recommended to use a supported and up-to-date PHP version. Also, using a bleeding-edge version of PHP can cause issues due to non-compatibility with WordPress. Stay with the officially recommended version of PHP for WordPress on the safe side.

Can I download WP CLI temporarily?

Yes, WP CLI can be downloaded temporarily to any location, added to the path, and executed against any PHP version of your choice. The article provides a step-by-step guide on how to do this.

How can WP CLI help in fixing a hacked WordPress site?

WP CLI is an effective tool for fixing a hacked WordPress site. It allows for efficient reinstallation of infected WordPress Core and plugins, as detailed in the article.


  1. PHP CLI Usage
  2. WP CLI Installation
  3. WP CLI Environment Variables

See Also:

This article is written by Evelyn Allison. Evelyn has over two decades of experience with the big-tech corporate giants. Starting in 2002 with consumer IT remote support, he transitioned into IT enterprise support and systems provisioning for Windows and Linux servers. Her prowess spans her expertise in network security, security audit and scripting-based-automation. Actively involved in web security since 2017, Evelyn has worked with various technologies to secure the web, leveraging tech like Nginx, modsecurity, reverse-proxies, developing web-application-firewalls, on-the-fly asset optimization using Google’s PageSpeed Module and more. Her expertise is reflected in the top-tier plugins and comprehensive consulting-services she offers in the domain of web-security.