3

On a development server I have a co-install of PHP 5.6 & 7; nginx is configured with PHP 5.6. When I type "wp" it returns several errors and at the end of the error is a message containing the following:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Typing wp --info returns:

PHP binary: /usr/bin/php7.0
PHP version: 7.0.10-2+deb.sury.org~precise+1
php.ini used: /etc/php/7.0/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI packages dir:
WP-CLI global config: /srv/www/wp-cli.yml
WP-CLI project config:
WP-CLI version: 0.26.0-alpha-5672b63

WP-CLI seems to be defaulting to PHP 7, I would prefer it to use PHP 5.6.

So I was wondering if there was an option I could add to the configuration yml file to select which PHP version to use?

If you need any further information, please let me know

  • By the time WP CLI loads the yml file, it's already running inside PHP, the answer to this will depend on your environment, OS, and how PHP is installed, take a look at stuff like PHPBrew etc – Tom J Nowell Oct 27 '16 at 15:03
  • As an aside, you should have mysqli installed, such an extension is available for PHP7 too, although the mysql extension is unsupported and should be avoided. Also, always work from the first error/warning down, the 2nd error may only occur when the 1st one occurs – Tom J Nowell Oct 27 '16 at 15:04
4

You can set the php binary that WP-CLI uses by setting an environment variable in your linux shell.

export WP_CLI_PHP=/path/to/php5.6
4

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.

0

Sounds like you need to change your default PHP version.

I assume php -v returns 7?

You'll need to change the PATH.

See this: https://stackoverflow.com/questions/31206864/use-different-php-version-cli-executable-for-one-command

Or this: https://wp-cli.org/docs/installing/#using-a-custom-php-binary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.