19

i'm trying to use rockmongo. After installation, i'm unable to use it. It says "To make things right, you must install php_mongo module. Here for installation documents on PHP.net."

i have already installed mongoDB driver extension via sudo pecl install mongo.

locate mongo shows /usr/lib/php5/20090626+lfs/mongo.so

However, php -v shows few warnings (which i think is related to mongo)

PHP:  syntax error, unexpected $end, expecting ']' in /etc/php5/cli/conf.d/mongodb.ini on line 3
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20100525+lfs/mongo.so' - /usr/lib/php5/20100525+lfs/mongo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.4.28-1+deb.sury.org~precise+1 (cli) (built: May  5 2014 09:39:26) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

i opened /usr/lib/php5/ and found out that there are another directory(20090626+lfs) which contains mongo.so.

i tried various online tutorial, but nothing helped.

Edit: Here's my mongodb.ini

;----- start -----
extension=mongo.so
\[mongo\]
; If the driver should reconnect to mongo
mongo.auto_reconnect = true
; Whether to allow persistent connections
mongo.allow_persistent = On
; Maximum number of persistent connections (-1 means unlimited)
mongo.max_persistent = -1
; Maximum number of links (persistent and non-persistent, -1 means unlimited)
mongo.max_connections = -1
; Default host for mongo connection
mongo.default_host = www.example.com
; Default port for mongo database
mongo.default_port = 42
; When saving files to the database, size of chunks to split them into
mongo.chunk_size = 1024
; Specify an alternate character to $ to use for special db functions ($set, $push, $exists, etc.)

mongo.cmd = "$"
;----- end -----
Kanav
  • 2,695
  • 8
  • 34
  • 56
  • possible duplicate of [mongo.so: > undefined symbol: php\_json\_encode in Unknown on line 0. After installation mongo driver for php](http://stackoverflow.com/questions/22952994/mongo-so-undefined-symbol-php-json-encode-in-unknown-on-line-0-after-instal) – Neil Lunn Jun 04 '14 at 06:17
  • i have already tried the solutions mentioned there. Didn't help. – Kanav Jun 04 '14 at 06:27
  • Edit your question to include your mongodb.ini file. Hint: `expecting ']' in /etc/php5/cli/conf.d/mongodb.ini on line 3` – Neil Lunn Jun 04 '14 at 06:29
  • Where can I find this mongodb.ini file?? – nclsvh Dec 03 '15 at 17:27

5 Answers5

13

I solved this problem using the 1.1.9 version of mongodb driver for php 5. First uninstall the current version of mongodb and then install the 1.1.9 version:

sudo pecl uninstall mongodb
sudo pecl install mongodb-1.1.9
composer update
J.C. Gras
  • 4,934
  • 1
  • 37
  • 44
  • Is this still uptodate? – kemicofa ghost May 11 '17 at 07:19
  • For me version 1.1.9 don't work. But I check latest version at https://pecl.php.net/package/mongodb (it was 1.4.4) and install it. All work fine. – Ilya Jun 20 '18 at 17:55
  • In fact, I installed the latest mongodb driver for php 7.2 and it worked fine. But for **php 5** version (this post) I recommend using the mongodb driver v1.1.9. For the current version it is only necessary to execute the command: `sudo pecl install mongodb` – J.C. Gras Jun 20 '18 at 23:09
9

My php version is 7.0, but it should work version 5.x too.

If you have this in the file /etc/php/7.0/mods-available/mongo.ini

extension=mongodb.so

Comment that line. After that restart php and it should work.

iled
  • 2,142
  • 3
  • 31
  • 43
David Ginosyan
  • 111
  • 1
  • 3
4

For me this works well

sudo apt-get install php7.2-mongodb

Change the '7.2' for your php version

cau
  • 572
  • 3
  • 9
1

Add the full path to your mongo.so extension in mongodb.ini:

extension=/usr/lib/php5/20090626+lfs/mongo.so

Also the [mongo] should be written exactly like that NOT \[mongo\].

Don't forget to reload/restart your web server to load the new configuration.

You can check that everything is ok with:

php -i | grep mongo 
Christian P
  • 12,032
  • 6
  • 60
  • 71
  • 1
    i edited `/etc/php5/apache2/php.ini` and changed `extension=mongo` to `extension=/usr/lib/php5/20090626+lfs/mongo.so`. Also, changed `\[mongo\]` to `[mongo]` in `etc/php5/apache2/conf.d/mongodb.ini`. Restarted apache. Still same error – Kanav Jun 04 '14 at 07:12
  • You changed the extension=mongo in `php.ini` but the error is in `mongodb.ini`. Remove the `extension=..` line from php.ini and change it in the `mongodb.ini` file. – Christian P Jun 04 '14 at 07:16
  • Same error. `php -v` shows `PHP Warning: PHP Startup: mongo: Unable to initialize module Module compiled with module API=20090626 PHP compiled with module API=20100525 These options need to match in Unknown on line 0` – Kanav Jun 04 '14 at 07:23
  • You had two errors: the one with invalid syntax and the one with wrong path to mongo.so file. What's your error now? – Christian P Jun 04 '14 at 07:27
  • both errors are gone now. But still i'm unable to open `localhost/rockmongo`. It says `To make things right, you must install php_mongo module. Here for installation documents on PHP.net.Also, i typed `php-v` again on terminal and it shows the above mentioned warning(unable to initialize module) – Kanav Jun 04 '14 at 07:30
  • Then go step by step. First, delete the mongodb.ini file and check with php -v that you don't have any errors. If no errors are showing, try to add mongodb.ini with only `extension` part. – Christian P Jun 04 '14 at 07:32
  • After, deleting `/etc/php5/apache2/conf.d/mongodb.ini`, `php -v` doesn't show any errors. i created `/etc/php5/apache2/conf.d/mongodb.ini` and included `extension=/usr/lib/php5/20090626+lfs/mongo.so`. Now same error. `These options need to match` – Kanav Jun 04 '14 at 07:41
  • That's the error you get when you're trying to load older modules with a newer version of php. Try to upgrade your mongo module and change the path to the new version. – Christian P Jun 04 '14 at 07:54
  • i tried `sudo pecl uninstall mongo` and then `sudo pecl install mongo`. Restarted Apache. Still `These options need to match`. – Kanav Jun 04 '14 at 08:01
  • https://stackoverflow.com/questions/19561722/pecl-installs-for-previous-php-version – Christian P Jun 04 '14 at 08:04
0

After OS update, I had a similar error while running any PHP CLI, simply running "php -v" produced the error:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/mongodb.so'

I checked the folder, I found the file '/usr/lib/php/20131226/mongodb.so' existed. So, I simply commented on the line "extension=mongo.so" in '/etc/php/5.6/cli/php.ini' file. It fixed my issue.

When checked mongo --version, it was working fine.

P Paneru
  • 1
  • 1