首页 > 解决方案 > gRPC extension not installed in the right PHP version in Ubuntu 18.04

问题描述

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

标签: phpubuntugrpc

解决方案


我这样做是通过特定版本的 php for pecl 来实现的,并确保将 php 版本设置为 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

在这里查看我的文章中的详细信息,我整合了 grpc 的最相关点,这也让我烦恼了几天:https ://ask.osify.com/qa/11804


推荐阅读