Cannot install mongoDB PHP driver

1,332 views
Skip to first unread message

Ian Rowett

unread,
Feb 25, 2016, 4:17:01 AM2/25/16
to mongodb-user, Ian Rowett
Using Mac 10.10.5, Apache 2.4 and PHP 5.5.32
- - - - - - - -

I have followed the steps to install the driver extension via PECL and Homebrew and both report that the extension is  installed. I have also installed the extension manually following the instructions on php.net as well as installing the mongodb-php-library from Github.

I have added the mongodb.so extension to the CLI /usr/local/etc/php/5.5/php.ini and the /etc/php.ini loaded in phpinfo(); I have also included extension=actual/path/to/mongodb.so (as reported after manually installing the driver) in both those php.ini files.

I have restarted server and OS several times including forcing HTTPD to quit using the Activity Monitor.

My phpinfo() says:

mongodb
mongodb support    enabled
mongodb version     1.1.3-dev
mongodb stability     devel
libmongoc version     1.3.3
libbson version     1.3.3

I tested the database in shell and can create databases, collections and documents.

I followed the instructions here: http://blog.mongodb.org/post/24960636131/mongodb-for-the-php-mind-part-1 but the script fails with:

PHP Fatal error:  Class 'Mongo' not found.

All the advice I’ve researched says that means the Mongo driver/extension is not installed.

What, in the name of all sanity, am I missing here?

Third (and final) day trying to install the PHP driver/extension for MongoDB before I cross the road to CouchDB :(

Any help will be much appreciated.

Thank you

Ian

Tim Hawkins

unread,
Feb 25, 2016, 4:24:01 AM2/25/16
to mongodb-user, Ian Rowett

It means  you are using the wrong classes, the new drivers have a different class hierarchy and namespace. Mongo is the connection class name for a very very old legacy driver, pre MongoClient 

You need to be using the new MongoDb\Driver classes

http://docs.php.net/manual/en/set.mongodb.php

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/7748f3d0-094b-42a5-aadd-b9ab9392d733%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Rowett

unread,
Feb 25, 2016, 4:36:47 AM2/25/16
to mongodb-user, i...@mintwebsolutions.com
Thanks for your quick response. I changed Mongo() to MongoDB\Driver\Manager() in the test script and same error is reported: class not found.

It may also be useful to note that I tried to install the DoctrineMongoDB Bundle for Symfony via composer and the install failed citing a lack of the mongoDB PHP extension. Not sure if the Bundle is out of date looking for the legacy driver you mentioned or if that indicates an install failure.

Derick Rethans

unread,
Feb 25, 2016, 5:23:32 AM2/25/16
to mongodb-user, i...@mintwebsolutions.com
On Thu, 25 Feb 2016, Ian Rowett wrote:

> Thanks for your quick response. I changed Mongo() to
> MongoDB\Driver\Manager() in the test script and same error is reported:
> class not found.

If you're using namespaces, that should be \MongoDB\Driver\Manager.

In any case, if phpinfo() both on the command line, and web browser
report that "mongodb 1.3.3-dev" is installed, than this should
definitely work:

<?php
$m = new \MongoDB\Driver\Manager();

> It may also be useful to note that I tried to install the
> DoctrineMongoDB Bundle for Symfony via composer and the install failed
> citing a lack of the mongoDB PHP extension. Not sure if the Bundle is
> out of date looking for the legacy driver you mentioned or if that
> indicates an install failure.

I don't believe it has been updated *yet* in a released version, but
work is being done on it:

- https://github.com/doctrine/mongodb-odm/issues/1292
- http://www.doctrine-project.org/2016/02/16/doctrine-mongodb-odm-release-1.0.5.html

cheers,
Derick

--
{
website: [ "http://mongodb.org", "http://derickrethans.nl" ],
twitter: [ "@derickr", "@mongodb" ]
}

Ian Rowett

unread,
Feb 25, 2016, 9:25:09 AM2/25/16
to mongodb-user, i...@mintwebsolutions.com
I cannot figure out why, but the phpinfo() in both command line and web interface is no longer showing mongodb enabled. However, trying to install again through Homebrew and Pecl still fails with the following:

Warning: homebrew/php/php55-mongodb-1.1.2 already installed

pecl/mongodb is already installed and is the same as the released version 1.1.2
install failed

In both php.ini files I have tried:

extension=mongodb.so

and

extension=/usr/local/Cellar/php55/5.5.32/lib/php/extensions/no-debug-non-zts-20121212/mongodb.so

Contents of /usr/local/Cellar/php55/5.5.32/lib/php/extensions/no-debug-non-zts-20121212/:

-rw-r--r--   1 ian    wheel     132732   8 Jan 01:11   ChangeLog
-rw-r--r--   1 ian    wheel     352         22 Feb 16:03 INSTALL_RECEIPT.json
-rw-r--r--   1 ian    wheel     11359     8 Jan 01:11    LICENSE
-rw-r--r--   1 ian    wheel     2430       8 Jan 01:11    README.md
-rwxr-xr-x 1 root   wheel     792704   25 Feb 10:02 mongodb.so

Followed by an Apache restart.

What's particularly odd is the version numbers have also changed.

Am I causing conflicts by trying all three install methods including the manual install?

Ian Rowett

unread,
Feb 25, 2016, 9:44:23 AM2/25/16
to mongodb-user
mongoDB support is re-enabled in phpinfo() - I had a syntax error after adjusting the error reporting in php.ini.

So back to square one. How to make a simple PHP query of a mongoDB instance after installing the appropriate PHP driver?

Thank you

Jeremy Mikola

unread,
Feb 25, 2016, 10:22:15 AM2/25/16
to mongod...@googlegroups.com
On Thu, Feb 25, 2016 at 9:44 AM, Ian Rowett <ianmr...@gmail.com> wrote:
mongoDB support is re-enabled in phpinfo() - I had a syntax error after adjusting the error reporting in php.ini.

So back to square one. How to make a simple PHP query of a mongoDB instance after installing the appropriate PHP driver?

You should be able to find a few examples in the PHP.net documentation, such as: http://php.net/manual/en/mongodb-driver-manager.executequery.php

I would also suggest using userland library, which provides a more robust API atop the "mongodb" extension (which was purposefully designed with a minimal API to ease in porting between PHP 5, PHP 7, and HHVM). There is a tutorial on PHP.net for the library at http://php.net/manual/en/mongodb.tutorial.library.php and we're also actively improving the official documentation, which is currently hosted via GitHub pages: http://mongodb.github.io/mongo-php-library/

While neither the new "mongodb" extension or the library will match the old "mongo" extension tutorials you've come across, I think you'll find that the userland library has a more familiar API (e.g. Client, Database, and Collection classes).

Ian Rowett

unread,
Mar 7, 2016, 2:03:44 AM3/7/16
to mongod...@googlegroups.com
Thank you for your assistance. I have it working now after wiping my VM, upgrading to PHP7 and manually installing the latest driver extension to the correct path.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/phcPSWv5mV8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
Reply all
Reply to author
Forward
0 new messages