简体   繁体   中英

mongo.so: > undefined symbol: php_json_encode in Unknown on line 0. After installation mongo driver for php

After installation of Mongo 2.6.0 which was successful, I tried to upgrade php mongo driver on ubuntu 12.04 with the following command: sudo pecl upgrade mongo . It started successfully with:

downloading mongo-1.5.1.tgz ...
Starting to download mongo-1.5.1.tgz (188,885 bytes)
.........................................done: 188,885 bytes
117 source files, building
running: phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
Build with Cyrus SASL (MongoDB Enterprise Authentication) support? [no]:

Where I selected No because when I tried yes, it was failing with error. With no I was able to install it successufully and the ending message looked like this:

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

After this I restarted apache ( 2.4.9 ), but my phpinfo() told me that mongo is not installed. On the other hand I can clearly see extension=mongo.so in my php.ini.

I checked my error.log and I can see the following line there:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/mongo.so' - /usr/lib/php5/20121212/mongo.so: undefined symbol: php_json_encode in Unknown on line 0

I checked my /usr/lib/php5/20121212/ and saw that there is actually a file mongo.so . I googled it and the only similar thing I was able to find is this , which is not really relevant, but having no other options I still tried steps there with no success.

Does anyone has an idea how to fix this?

The issue is with the loading order, so the json extension needs to be loaded before mongo.so is loaded.

Since others are likely to come across this I will outline the whole process:

  • In your /etc/php/mods-available directory (or as appropriate to platform) create a separate mongo.ini with the following:
; configuration for php mongo module
; priority=30
extension=mongo.so
  • Remove any other references to mongo.so from other files such as php.ini

  • Create symlinks in each of the cli and apache2 directories as required for use as so:

sudo ln -s ../../mods-available/mongo.ini 30-mongo.ini

At end of this you should have a structure that looks like this

$/etc/php5$ tree
.
├── apache2
│   ├── conf.d
│   │   ├── 05-opcache.ini -> ../../mods-available/opcache.ini
│   │   ├── 10-pdo.ini -> ../../mods-available/pdo.ini
│   │   ├── 20-json.ini -> ../../mods-available/json.ini
│   │   ├── 20-readline.ini -> ../../mods-available/readline.ini
│   │   └── 30-mongo.ini -> ../../mods-available/mongo.ini
│   └── php.ini
├── cli
│   ├── conf.d
│   │   ├── 05-opcache.ini -> ../../mods-available/opcache.ini
│   │   ├── 10-pdo.ini -> ../../mods-available/pdo.ini
│   │   ├── 20-json.ini -> ../../mods-available/json.ini
│   │   ├── 20-readline.ini -> ../../mods-available/readline.ini
│   │   └── 30-mongo.ini -> ../../mods-available/mongo.ini
│   └── php.ini
└── mods-available
    ├── json.ini
    ├── mongo.ini
    ├── opcache.ini
    ├── pdo.ini
    └── readline.ini

This makes sure that the "json" extension will be loaded by the dynamic loader before the "mongo" module is.

But basically remove the mongo.so from "php.ini" and put it in it's own file with higher loading order than the json extension. Then it will work.

This possibly needs a JIRA as I believe it has come up before.

UPDATE : Actually is an open JIRA PHP-1052

my system is centos 6.3. I got the problem solved.

vim /etc/php.ini

then add

extension=json.so

before

extension=mongo.so

at last restart the php-fpm and nginx(apache)

service php-fpm restart
service ngxin restart

It's OK!

For someone who is looking for a fast solution, here is my few lines, which utilize Neil's Lunn long explanation about the problem.

sudo -i
cd /etc/php5/mods-available/
nano mongo.ini

Than insert this:

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

Go out from the editor.

cd ../cli/conf.d
sudo ln -s ../../mods-available/mongo.ini 30-mongo.ini
cd ../../apache2/conf.d
sudo ln -s ../../mods-available/mongo.ini 30-mongo.ini

Restart apache.

service apache2 restart

Everything should work.

You need to load the json extension before the mongo extension.

Don't put any reference to both modules in php.ini,

Create the file mongo.ini inside /etc/php5/mods-enable with the following content:

priority=30
extension=mongo.so

and the json.ini

priority=20
extension=json.so

对于CentOS,你只需要在php模块目录中添加mongo.ini,在我的例子中:

"/etc/php.d/"

For Ubuntu 14.04 you can also add a "30-mongo.ini" symlink under these:

/etc/php5/cgi/conf.d
/etc/php5/fmp/conf.d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM