4

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
Jonatan Lavado
  • 954
  • 2
  • 15
  • 26
  • Did you try to just do `sudo pecl install grpc` as mentioned in the link https://grpc.io/docs/languages/php/quickstart/#using-pecl you mentioned? – Stanley Cheung Jul 08 '20 at 18:13
  • `/usr/lib/php/20180731/grpc.so` seems to suggest that Apache was installed with PHP 7.3, while in your command line installation of the extension `/usr/lib/php/20190902/` seems to indicate that your cli PHP is on PHP 7.4. There seems to be a version mismatch there. – Stanley Cheung Jul 08 '20 at 18:27
  • @StanleyCheung I added an answer. Thanks for your help tho. – Jonatan Lavado Jul 08 '20 at 20:28

2 Answers2

10

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

Osify
  • 2,253
  • 25
  • 42
5

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
Jonatan Lavado
  • 954
  • 2
  • 15
  • 26