php安装mongodb扩展时PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/m...

背景

在homestead中给php7.1版本安装mongodb扩展,使用shell pecl install mongodb安装完之后在php.ini文件中添加extenstion=mongodb.so,运行php -m 提示 code PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/mongodb.so' - /usr/lib/php/20160303/mongodb.so: cannot open shared object file: No such file or directory in Unknown on line 0
发现pecl install mongodb 安装到了/usr/lib/php/20180731这个文件夹中。

排错

各种google之后发现需要自己编译安装
1.下载mongodb扩展源码,并解压

wget https://pecl.php.net/get/mongodb-1.6.0.tgz
tar -zxvf mongodb-1.6.0.tgz
  1. 查找phpize的执行文件
whereis phpize
image.png

3.选择合适的phpize,生成configure文件(我需要/usr/bin/phpize7.1 )

cd mongodb-1.6.0
/usr/bin/phpize7.1

4.查找php-config

whereis php-config
image.png

5.编译安装

./configure --with-php-config=/usr/bin/php-config7.1
make && make install

6.验证

php -m

思考

看到有一篇文章说可以通过改pecl的配置来实现用pecl给不同的版本安装扩展 https://www.jianshu.com/p/fee58d93e8b1
但是我用pecl config-show 查看我配置,发现我的php扩展目录是20160303,但是安装依然为安装到20180731,不知道为什么,看pecl install mongodb执行的过程,会使用phpize,而这个phpize显示的目录就是20160303,自己不是很懂底层的加载原理。以后对于系统有多个php版本安装扩展还是建议手动编译安装。

homestead中切换php版本

update-alternatives --config php

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容