WP-CLI – Selecting PHP version

Got the same problem! Just switch the php version.
On my server PHP5.6 was default for apache, while CLI was configured with PHP7.1. After installing WP-CLI, with wp --info I got this result:

PHP binary: /usr/bin/php7.1
PHP version: 7.1.5-1+deb.sury.org~xenial+1
php.ini used: /etc/php/7.1/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar

And when i used the wp core install command i got the error: Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
The problem is just the mix between the different versions: we have just to switch completely to 5.6 or 7.1.
In my case problem was solved simply by writing on the shell:

sudo update-alternatives --set php /usr/bin/php5.6

And then wp --info

PHP binary: /usr/bin/php5.6
PHP version: 5.6.30-10+deb.sury.org~xenial+2
php.ini used: /etc/php/5.6/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar

Problem solved! WP-CLI worked like a charm.

Leave a Comment