'GRPC installed successfully on ubuntu but php is looking for it in another folder

Using PHP 7.4 & Ubuntu 20.04 LTS

I have installed GRPC using these steps:

sudo apt-get install autoconf zlib1g-dev php-dev php-pear
sudo pecl install grpc

I then added the following line to the folder shown for both cli and fpm

extension=grpc.so
/etc/php/7.4/cli/php.ini
/etc/php/7.4/fpm/php.ini

When I then run php I get the following error:

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

After install pecl outputted that it was installed here:

/usr/lib/php/20200930/grpc.so

Trying to be clever I thought I could just copy the file to where php was expecting it:

sudo cp /usr/lib/php/20200930/grpc.so /usr/lib/php/20190902/grpc.so

But when you run php after you get the following:

PHP Warning:  PHP Startup: grpc: Unable to initialize module
Module compiled with module API=20200930
PHP    compiled with module API=20190902
These options need to match

Any ideas?



Solution 1:[1]

Install with the below command

sudo pecl -d php_suffix=8.1 install grpc

Initially i had php7.4 and php8.1 versions. Default version was php8.1 and was trying to install for the same. But for some reason it was installing in the wrong folder (/usr/lib/php/20200930/grpc.so). Removing php7.4 did not help.

Installing specific to php8.1 solved the issue.

Make sure to remove any previous versions

sudo pecl uninstall grpc

Solution 2:[2]

same issue anyone

PHP Warning: PHP Startup: Unable to load dynamic library 'grpc.so' (tried: /usr/lib/php/20190902/grpc.so (/usr/lib/php/20190902/grpc.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/grpc.so.so (/usr/lib/php/2 0190902/grpc.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

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 Lokesh
Solution 2 Nhama23