Re: PHP Mongo driver on Ubuntu - Fatal error: Class 'Mongo' not found

4,908 views
Skip to first unread message

Adam Monsen

unread,
Nov 15, 2012, 3:44:04 PM11/15/12
to mongod...@googlegroups.com, RP
Will you provide the actual error message(s) you're seeing and example
code that causes the error?

On 11/15/2012 12:04 PM, RP wrote:
> I know this error has come up a lot from incorrect installations, but I
> feel as if I've been pretty diligent and I just can't get past it.
>
> -Running PHP 5.3.5-1ubuntu7.3 with Suhosin-Patch (cli)
> -Installed Mongo PHP driver using pecl (sudo pecl install mongo) without
> error
> -Ran php --ini to be sure I had correct location of php.ini file
> -Added extension=mongo.so to the active php.ini file
> -Restarted Apache
> -Ran php --ri mongo (MongoDB Support = enabled)
>
> Everything seems like it should be working, but the error persists.
> Another thing to note in case of relevance: mongod is not installed on
> this server, just the PHP driver, dbs are not on localhost but on
> separate server.
>
> Any help is much appreciated.


signature.asc

RP

unread,
Nov 19, 2012, 1:38:00 PM11/19/12
to mongod...@googlegroups.com, RP
Thanks, Adam. Let me know if this isn't enough:

Sample error: 
Fatal error: Class 'Mongo' not found in /var/www/app/models/grid_file.php on line 243

Sample code to which this error points ("$m =" is the line that is called in the error).

        public function getFileInfoByMetadata($conditions){
                $m = new Mongo(MONGOCONNECT);
                $db = $m->selectDB(MONGODB);
                $grid = $db->getGridFS();
                $files = $grid->find($conditions);

RP

RP

unread,
Nov 19, 2012, 1:40:38 PM11/19/12
to mongod...@googlegroups.com
Christophe,

I do not have a mongodb.ini file present on the server after install and I wasn't aware of one being used in configuration. Is this typical?

RP

On Friday, November 16, 2012 12:05:02 PM UTC-5, Christophe Hurpeau wrote:
Could you try adding extension=mongo.so
in : /etc/php5/conf.d/mongodb.ini
?


Le jeudi 15 novembre 2012 21:04:15 UTC+1, RP a écrit :
I know this error has come up a lot from incorrect installations, but I feel as if I've been pretty diligent and I just can't get past it.

-Running PHP 5.3.5-1ubuntu7.3 with Suhosin-Patch (cli)
-Installed Mongo PHP driver using pecl (sudo pecl install mongo) without error
-Ran php --ini to be sure I had correct location of php.ini file
-Added extension=mongo.so to the active php.ini file
-Restarted Apache
-Ran php --ri mongo (MongoDB Support = enabled)

Everything seems like it should be working, but the error persists. Another thing to note in case of relevance: mongod is not installed on this server, just the PHP driver, dbs are not on localhost but on separate server.

Any help is much appreciated.

RP


jm

unread,
Nov 19, 2012, 2:31:48 PM11/19/12
to mongod...@googlegroups.com
> Ran php --ini to be sure I had correct location of php.ini file

That does not necessarily work with apache.

You can create a PHP file with the following contents:

<?php
phpinfo();
?>

Open that in your browser through apache, and you should find the correct php.ini file location. Also if mongo is successfully installed, you should find a Mongo section there with additional info.

Adam Monsen

unread,
Nov 26, 2012, 2:17:58 PM11/26/12
to mongod...@googlegroups.com, RP, RP
Thanks. It looks like others have provided good help. Have you tried
what jm suggested in
http://article.gmane.org/gmane.comp.db.mongodb.user/82927 ? You'll
likely find that the MongoDB PHP extension is not loaded.

Regarding Christophe's comment in
http://article.gmane.org/gmane.comp.db.mongodb.user/82785 , I believe it
is standard operating procedure on Ubuntu to create
/etc/php5/conf.d/mongo.ini manually. Mine contains the following:

extension=mongo.so

I hope this helps!

Please follow up and let us know if you got it to work, and how.

-Adam
signature.asc

Matthew Herbst

unread,
Jan 19, 2014, 3:32:02 AM1/19/14
to mongod...@googlegroups.com
I can confirm that this fix works. Took me a few hours to find this thread, but thank you!

On Friday, March 1, 2013 10:04:02 AM UTC-5, Lucas Serafim wrote:
I had the same problem but the answer of Christophe Hurpeau solved!

In my case I check where is the config.d/ folder with php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d

Then, create the mongodb.ini with the content "extension=mongo.so"
$ sudo vi /etc/php5/cli/conf.d/mongodb.ini

Thanks

On Friday, November 16, 2012 11:05:02 AM UTC-6, Christophe Hurpeau wrote:
Could you try adding extension=mongo.so
in : /etc/php5/conf.d/mongodb.ini
?

Le jeudi 15 novembre 2012 21:04:15 UTC+1, RP a écrit :
Reply all
Reply to author
Forward
0 new messages