2

I just got errors when I try to install MongoDB PHP Library:

$ 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

When I execute phpinfo() I can see the following:

mongodb

mongodb support enabled
mongodb version 1.2.1
mongodb stability   stable
libmongoc version   1.5.0
libbson version 1.5.0

When I execute locate mongodb.so here's where my mongodb.so file is:

/usr/lib/php/20151012/mongodb.so

As I can notice, this is the path where 20-mongodb.ini file is:

/etc/php/7.0/apache2/conf.d

Also, sudo pecl mongodb install returns the following:

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 returns:

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 <[email protected]> (lead)
                      Jeremy Mikola <[email protected]> (lead)
                      Derick Rethans <[email protected]> (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

I searched on Google for a few hours, but still nothing. Thank you.

4 Answers 4

6

Yes, there are good answers. Here's what I did to install mongo in php7.1. I am using ubuntu16.04 64bit:

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

It it all for nginx. If you are using apache, please add:

echo 'extension=mongodb.so' | sudo tee /etc/php/7.1/apache2/conf.d/30-mongodb.ini

And one more. If you continue to have an error when working with mongo. Something like that:

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

Do not despair, run the following commands:

sudo pecl uninstall mongodb
sudo pecl install mongodb
Sign up to request clarification or add additional context in comments.

Comments

4

First type this command /usr/bin/php-config to see where the extension directory is.
You will see something like this --extension-dir [/usr/lib/php/20131226] Than ls in that folder see if the mongo.so is there , if not put it there.
Type whereis php to locate the php you are using in CLI
Edit the php.ini for the CLI and add the extension=mongo.so

4 Comments

Thank you for the answer. My extension directory is here: /usr/lib/php/20151012 and mongodb.so is there (not mongo.so because that's deprecated). Anyway, here's loaded configuration file: /etc/php/7.0/apache2/php.ini with additional ini files in the following directory /etc/php/7.0/apache2/conf.d where 20-mongodb.ini file is.
Hi, you have to add the extension=mongodb.so inside the /etc/php/7.0/cli/php.ini and it should work.
thank you. The whole day I'm solving this issue but still nothing. When I type php --ini I simply get the following error: 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 Anyway, this might be a solution: derickrethans.nl/undefined-symbol.html but still nothing.
This is a different error now i think, you can refer here
0

Use the 1.1.9 mongodb version:

sudo pecl uninstall mongodb
sudo pecl install mongodb-1.1.9
composer update

Comments

0

I did as @Andrinux and @J.C. Gras suggestions and I got an error phpize not found.

So I did research and found this How to install and run phpize. This is because php-dev was not installed on my system, so I did install it.

In the sequence, I did:

// Ubuntu 20.04.3
$ sudo apt-get update
$ sudo apt install php-dev
$ sudo pecl install mongodb (at the time, it installed mongodb-1.10.0)

If you see this message, the extension has successfully installed

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0" install
Installing shared extensions:     /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0/usr/lib/php/20200930/
running: find "/tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0" | xargs ls -dils
52067    4 drwxr-xr-x 3 root root    4096 Sep 28 16:18 /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0
52629    4 drwxr-xr-x 3 root root    4096 Sep 28 16:18 /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0/usr
52630    4 drwxr-xr-x 3 root root    4096 Sep 28 16:18 /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0/usr/lib
52631    4 drwxr-xr-x 3 root root    4096 Sep 28 16:18 /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0/usr/lib/php
52632    4 drwxr-xr-x 2 root root    4096 Sep 28 16:18 /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0/usr/lib/php/20200930
52627 8708 -rwxr-xr-x 1 root root 8916120 Sep 28 16:18 /tmp/pear/temp/pear-build-rootDvmP4U/install-mongodb-1.10.0/usr/lib/php/20200930/mongodb.so

Build process completed successfully
Installing '/usr/lib/php/20200930/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.10.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.ini

Don't forget to restart PHP-FPM and APACHE server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.