Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mongodb - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...