6

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

After installing MongoDB I'm now get this error whenever I run any php command from terminal:

php artisan

php -v

I have searched for 2 days now. I have seen these:

PHP unable to load dynamic library (mongo.so)

https://github.com/mongodb/mongo-php-library/issues/126

and I'm pretty sure any other solution that comes up from google this error. They all seem to be fixes for php5 and ain't working for me.

I have added extension=mongodb.so to ini files.

I have destroyed VM and started fresh 100 times.

I'm running: Vagrant 1.8.5 Laravel Installer version 1.3.3

vagrant@homestead:~$ php -v 

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
7.0.13-1+deb.sury.org~xenial+1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
    with blackfire v1.14.1~linux-x64-non_zts70, https://blackfire.io, by Blackfireio Inc.

Mongo is installed and running fine:

vagrant@homestead:~$ mongo
MongoDB shell version v3.4.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.0
Server has startup warnings: 
2016-12-05T15:32:01.158+0000 I STORAGE  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-12-05T15:32:01.205+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-12-05T15:32:01.205+0000 I CONTROL  [initandlisten] 
> 

But I can't stop this php error for nothing in the world!!!

1
  • I'm having the exact same problem. I haven't found a solution yet, but the problem might be related to the 1.1.0 release from yesterday: github.com/mongodb/mongo-php-library/releases. Commented Dec 7, 2016 at 13:59

2 Answers 2

13

I think the problem is here that mongodb.so depends on json.so. The solution is to load mongodb.so after json.so.

I guess you are using the custom Mongo script for Homestead. The script outputs the mongodb.so module in php.ini file with the result that mongodb.so is loaded first. You should create a mongodb.ini file where mongodb.so is loaded.

Create the .ini-file: /etc/php/7.0/mods-available/mongodb.ini with content:

; configuration for php mongo module
; priority=30
extension=mongodb.so

Give it priority 30, since json gets 20 (in my settings) to be sure it is loaded afterwards.

Create a softlink of the ini-file to /etc/php/7.0/fpm/conf.d to make it available for the webserver.

ln -s /etc/php/7.0/mods-available/mongodb.ini 30-mongodb.ini

Reload webserver and php-fpm.

sudo service [your webserver] restart && sudo service php7.0-fpm restart

You are done! You can config the cli-version the same way

Sign up to request clarification or add additional context in comments.

4 Comments

This works great for php 7.1 too, just swap out 7.0 to 7.1 in the paths.
Works like a charm! :D I have been searching the whole morning about a solution! Thanks! PS.: I didn't configure the cli-version. Is it necessary?
Cli-version is only necessary if you're using packages that use cli (in background). For instance, the moloquent (mongo for Laravel) requires cli when you install it via composer.
Does not work. Still getting the same error on CLI for php 7.1. Have restarted php7.1-fpm and nginx
3

I had the same problem, I solved it by reverting to an older PECL mongodb version (1.1.9). There was an update to version 1.2.0 on November 29th, which is why the mongo-php-library also got updated to version 1.1.0.

Here is what I did:

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

The pecl commands will show the same warning, but the installation was successfully completed.

I hope that the mongo-php-library will be fixed soon, so we're not stuck using an older PECL extension.

2 Comments

Chris is right. Make sure it is loaded after json extension
Yep, I saw that, it's a much better solution.

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.