PHP Fatal error: Class 'Mongo' not found

9,152 views
Skip to first unread message

glowens

unread,
Jan 5, 2011, 8:06:05 PM1/5/11
to mongodb-user
I am sure there is a simple solution to this issue but for the life of
me I can't figure it out....

I am getting a "PHP Fatal error: Class 'Mongo' not found.." I
followed the install direction and everything appears to have loaded
properly. I can see that the driver is loaded using phpinfo(). It
appears I have all permission correct. I have the same file running
on another machine and it works perfectly. The only thing different
is I am now trying to run the php script on the same machine as the
MongoDB. The MongoDB was installed before the mongo php driver.
Could it be the DB must be on a separate machine from the PHP script
or how the mongo db was installed?

My connection string
<?php
$connection = new Mongo();
//$connection = new Mongo("localhost");
$db = $connection->database1;
$collection = $db->hits;

Thanks
G

Nat

unread,
Jan 5, 2011, 8:12:05 PM1/5/11
to mongodb-user
what is your php/os version?

Kristina Chodorow

unread,
Jan 5, 2011, 9:31:31 PM1/5/11
to mongod...@googlegroups.com
That error means the extension isn't being loaded.  Are you running phpinfo() from the same PHP process that you're running that script?  The command line uses a different PHP than your application server (which is where I'm guessing you're running phpinfo()).  If you're running the script from the command line, run php -i.

You can install the driver and database in any order and they should work.
 

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Sam Millman

unread,
Jan 6, 2011, 3:03:45 AM1/6/11
to mongod...@googlegroups.com
try these packages:

php5-dev
php-pear

then do:

pecl install mongo

then add:

extension=mongo.so

to the end of your php.ini
--
Bow Chicka Bow Wow

sdotsen

unread,
Jan 6, 2011, 9:47:42 AM1/6/11
to mongodb-user
I forget which distro I was using but there's a separate "php.ini"
file for the CLI. I found out the hard way when I was testing Mongo
via PHP's CLI. I had the extension listed in /etc/php.ini (for web
use) but for the life of me couldn't figure out why PHP couldnt load
the Mongo class via CLI. Low and behold, php-cli.ini or something like
that didn't have the extension.


On Jan 6, 3:03 am, Sam Millman <smill...@nhbs.co.uk> wrote:
> try these packages:
>
> php5-dev
> php-pear
>
> then do:
>
> pecl install mongo
>
> then add:
>
> extension=mongo.so
>
> to the end of your php.ini
>
> On 6 January 2011 02:31, Kristina Chodorow <krist...@10gen.com> wrote:
>
>
>
>
>
>
>
>
>
> > That error means the extension isn't being loaded.  Are you running
> > phpinfo() from the same PHP process that you're running that script?  The
> > command line uses a different PHP than your application server (which is
> > where I'm guessing you're running phpinfo()).  If you're running the script
> > from the command line, run php -i.
>
> > You can install the driver and database in any order and they should work.
>
> >> mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/mongodb-user?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>
> > .

glowens

unread,
Jan 6, 2011, 9:58:33 AM1/6/11
to mongodb-user
Crap! Forget about the cli php.ini file. I knew it was something
simple.

G

On Jan 5, 9:31 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> That error means the extension isn't being loaded.  Are you running
> phpinfo() from the same PHP process that you're running that script?  The
> command line uses a different PHP than your application server (which is
> where I'm guessing you're running phpinfo()).  If you're running the script
> from the command line, run php -i.
>
> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages