gRPC extension not installed in the right PHP version in Ubuntu 18.04

Viewed 7304

I'm trying to install gRPC extension following the official guidance

I've followed all the steps, but on these final steps, I get this (which I think will matter later)

$ cd grpc/src/php/ext/grpc
$ phpize
$ ./configure
$ make
$ sudo make install

Installing shared extensions: /usr/lib/php/20190902/

Here, I checked that folder and found the grpc.so file.

At this point, I expected to have the extension installed, I've added extension=grpc.so within php.ini (apache2 and cli). But it doesn't work.

I tried to verify it but it returns false: var_dump(extension_loaded('grpc')); => bool(false)

Now, I've checked the apache2 log file and I saw this:

PHP Warning: PHP Startup: Unable to load dynamic library 'grpc.so' (tried: /usr/lib/php/20180731/grpc.so (/usr/lib/php/20180731/grpc.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/grpc.so

The possible error?

What I think is, after install the grpc extension it was installed in /usr/lib/php/20190902/ (as you saw before). But apache is trying to find it in /usr/lib/php/20180731/grpc.so

I don't know what I'm doing wrong. I think I edited the right php.ini files because when I do php_info() I get this:

Configuration File (php.ini) Path   /etc/php/7.3/apache2
Loaded Configuration File   /etc/php/7.3/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.3/apache2/conf.d
2 Answers

I did this way instead by specific version of php for pecl and make sure you make your php version as default one in the ubuntu:

# modules of php 7.3 (state your correct version)
sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl -y

# module require
sudo apt-get install php-pear phpunit

# if you have previous version of grpc, uninstall it
pecl uninstall grpc

# install grpc base on specific version
pecl -d php_suffix=7.3 install grpc

Check detail in my article here, I consolidate most related point of grpc that annoyed me for few days too: https://ask.osify.com/qa/11804

I've solved it. Apparently pecl needed to be configurated on what PHP version I wanted it to be installed. Something like this, it was being installed on the latest version I have, the 7.4. But I needed it to be in the 7.3 version:

# cd ./grpc

# phpize7.3

# ./configure --with-php-config=/usr/bin/php-config7.3

# make clean

# make

# make install
Related