我尝试安装MongoDB PHP库时遇到错误:
$ composer require "mongodb/mongodb=^1.0.0"
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
当我执行phpinfo()
时,我可以看到以下内容:
mongodb
mongodb support enabled
mongodb version 1.2.1
mongodb stability stable
libmongoc version 1.5.0
libbson version 1.5.0
当我执行定位mongodb.so时,我的mongodb.so文件位于:
/usr/lib/php/20151012/mongodb.so
我可以注意到,这是20-mongodb.ini
文件所在的路径:
/etc/php/7.0/apache2/conf.d
此外,sudo pecl mongodb install
会返回以下内容:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
sudo pecl info mongodb
返回:
About pecl.php.net/mongodb-1.2.1
================================
Release Type PECL-style PHP extension (source code)
Name mongodb
Channel pecl.php.net
Summary MongoDB driver for PHP
Description The purpose of this driver is to provide
exceptionally thin glue between MongoDB
and PHP, implementing only fundemental and
performance-critical components
necessary to build a fully-functional MongoDB
driver.
Maintainers Hannes Magnusson <bjori@php.net> (lead)
Jeremy Mikola <jmikola@php.net> (lead)
Derick Rethans <derick@php.net> (lead)
Release Date 2016-12-07 18:25:03
Release Version 1.2.1 (stable)
API Version 1.2.1 (stable)
License Apache License
(http://www.apache.org/licenses/LICENSE-2.0)
Release Notes ** Bug
* [PHPC-848] - Fix BSON encoding of
immutable arrays and documents with circular
references
Required Dependencies PHP version 5.4.0-7.99.99
PEAR installer version 1.4.8 or newer
package.xml version 2.0
Last Modified 2016-12-09 00:28
Previous Installed 1.2.0
Version
我在Google上搜索了几个小时,但仍然没有。谢谢。
答案 0 :(得分:5)
是的,有很好的答案。 这是我在php7.1中安装mongo所做的。我使用的是ubuntu16.04 64位:
sudo aptitude install -y php7.1-dev pkg-config
sudo -H pecl channel-update pecl.php.net
sudo aptitude install -y libcurl4-openssl-dev pkg-config libssl-dev libsslcommon2-dev
sudo pecl install mongodb
echo 'extension=mongodb.so' | sudo tee /etc/php/7.1/fpm/conf.d/30-mongodb.ini
echo 'extension=mongodb.so' | sudo tee /etc/php/7.1/cli/conf.d/30-mongodb.ini
sudo systemctl restart php7.1-fpm.service
这一切都适用于nginx。如果您使用的是apache,请添加:
echo 'extension=mongodb.so' | sudo tee /etc/php/7.1/apache2/conf.d/30-mongodb.ini
还有一个。如果在使用mongo时仍然出错。这样的事情:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/mongodb.so' - libssl.so.1.0.2: cannot open shared object file: No such file or directory in Unknown on line 0
不要绝望,请运行以下命令:
sudo pecl uninstall mongodb
sudo pecl install mongodb
答案 1 :(得分:3)
首先输入此命令/usr/bin/php-config
以查看扩展目录的位置
您会看到类似--extension-dir [/usr/lib/php/20131226]
的内容
比该文件夹中的ls
更多,看看mongo.so
是否存在,如果没有,请将其放在那里
输入whereis php
以找到您在CLI
中使用的php
编辑CLI的php.ini并添加extension=mongo.so
答案 2 :(得分:0)
使用1.1.9 mongodb版本:
sudo pecl uninstall mongodb
sudo pecl install mongodb-1.1.9
composer update