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:
/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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With