'gRPC library is installed but doesn't work [duplicate]

I'm having a error with google Firestore PHP Api, when I try to connect to Firestore the server return me this error: The requested client requires the gRPC extension. Please see https://cloud.google.com/php/grpc for installation instructions. The error comes from vendor/google/cloud/Core/src/ClientTrait.php because the function isGrpLoaded response with a false:

/**
 * Abstract the checking of the grpc extension for unit testing.
 *
 * @codeCoverageIgnore
 * @return bool
 */
protected function isGrpcLoaded()
{
    return extension_loaded('grpc');
}

I already installed gRPC following this instructions from google https://cloud.google.com/php/grpc. I install PECL, install Composer, install the gRPC extension, add the grpc extension to php.ini file, install the Protobuf Runtime library and also add the protobuf extension to php.ini.

So in my composer I have this lines:

...
google/grpc-gcp                       0.1.3    gRPC GCP library for channel management
google/protobuf                       v3.6.1   proto library for PHP
grpc/grpc                             1.15.0   gRPC library for PHP
...

In my php.ini file I have this two new lines:

extension=protobuf.so
extension=grpc.so

The problem comes here, when I execute in my server terminal this line:

sudo php -r "echo extension_loaded('grpc') ? 'yes' : 'no';"

the server response me with a yes, everything seems fine.

But if I create an php file like this:

<?php
  echo extension_loaded('grpc') ? 'yes' : 'no';
?>

The response is no.

I'm using

Ubuntu 16.04.5 LTS 
PHP 7.2.13


Solution 1:[1]

If you're using Nginx and PHP FPM is running then php --ini may be outputting the wrong path of your ini file. You should use phpinfo() to check for the exact path.

In my case, having referenced php --ini, I was incorrectly updating /etc/php/7.2/cli/php.ini when the actual file was /etc/php/7.2/fpm/php.ini.

On updating the correct file and restarting FPM with systemctl restart php7.2-fpm.service phpinfo() output a section on gRPC.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nick