最近项目上需要使用MongoDb来存储日志数据,但是当我去执行pecl install mongodb时却报错,报错内容如下:
pecl install mongodb
Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187 PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187 PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187 Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187 PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update pecl/mongodb requires PHP (version >= 8.1.0, version <= 8.99.99), installed version is 7.4.3-4ubuntu2.28
No valid packages found
install failed
可见mangodb扩展最新版已经不支持php7.4了,找了一下发现支持php7.4的扩展最新版本为mongodb-1.20.1,所以使用pecl install mongodb-1.20.1来安装就Ok了
补充php7.4安装mongodb扩展的方法:
Windows:
https://pecl.php.net/package/mongodb/1.20.1/windows下载对应版本
Linux:
pecl install mongodb-1.20.1
记录于2025年3月7日