I’ve encountered following error when running mongodb php module
Dec 12 09:56:02 lj php-fpm: [12-Dec-2016 09:56:02] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mongodb.so' - /usr/lib64/php/modules/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
Few google searches reveal this can be fixed by simply making sure json is loaded prior to mongodb.so – which by default isn’t.
There are many ways to do that, for example find how your json is loaded
[root@lj php.d]# php -i | grep "json" /etc/php.d/json.ini,
Now open json.ini and add
at the end – and remove mongodb.ini from the folder.
Or rename json.ini to 20-json.ini and mongodb.ini to 30-mongodb.ini
You can also add priority at top of the ini file priority=30
Don’t forget to restart php after each change, if you are running mod_php, just do systemctl restart httpd, for php-fpm it’s systemctl restart php-fpm.
Now the weird thing is – none of this worked for me.
No matter how I loaded mongodb, it always failed with this error. I got the latest pecl packages, everything up to date – it simply didn’t work.
The only solution for me was to roll back to previous version of mongodb
[root@lj php.d]# pecl uninstall mongodb [root@lj php.d]# pecl install mongodb-1.1.9 [root@lj php.d]# echo "extension=mongodb.so" > /etc/php.d/zz-99-mongo.ini
I called the file zz-99 to make sure it’s always loaded last. My ini files do not start with 20-*.ini to set priority.