Recently I was migrating a website from GoDaddy shared hosting using WP-CLI and noticed the PHP version in cli was outdated.
Here is how to install WP-CLI and set custom PHP version for the cli.
Setup WP-CLI
To download WP cli:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharTo run it use php wp-cli.phar
php wp-cli.phar --infoTo make it easier to call We’ll rename it to wp:
sudo mv wp-cli.phar wpand make it executable:
chmod +x wpTo add WP-CLI to path run:
export PATH=</path/to/wp-cli/directory>:$PATHand afterwards you can use the wp command inside any directory
wp --infoCheck PHP version for terminal
From the terminal run
php -versionOr, create an info.php page with phpinfo(); and under Configure Command options look for bindir
bindir=/opt/cpanel/alt-php80/root/usr/binSet PHP version for the cli
Set the WP_CLI_PHP environment variable to the desired PHP version:
export WP_CLI_PHP=/opt/php81/binWas this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂

