Installing the PHP 7 MongoDB Client/Driver? Installing the PHP 7 MongoDB Client/Driver? mongodb mongodb

Installing the PHP 7 MongoDB Client/Driver?


The Mongo extension for PHP Version 5.99.99 or older has been superseded:

https://pecl.php.net/package/mongo

Use the newer one for PHP Version 7.99.99 or older instead:

https://pecl.php.net/package/mongodb

You can install a PECL/PEAR extension automatically:

pecl install mongodb

or manually.

The classes have been changed too:

new \MongoClient(); // legacy class!

see http://php.net/manual/en/book.mongo.php

new \MongoDB\Driver\Manager(); // new classes! 

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

Additional information regarding compatibility can be found here:

https://docs.mongodb.org/ecosystem/drivers/php/#compatibility


The MongoDB driver that supports PHP 7 was only released December 22nd - its likely downstream repositories like brew haven't updated.

Update confirmed there is currently no php70-mongo brew script, though there is an active pull request to add one.

You may be able to install it manually via pecl in the meantime:

pecl channel-update pecl.php.netpecl install mongodbecho "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`


How to connect php 7.0 with MongoDB in ubuntu 16.04 lts?

1)Install LAMP using the following link. It installs Apache2, mysql and php 7.0.https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04

2)Install the MongoDB community Edition on Ubuntu using the steps in the following link.http://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

3)Type the following command to get the mongoDB extension from pecl

sudo apt install php-pear

4)Add the following to the php.ini file at /etc/php/apache2/7.0

extension=mongodb.so

Important - The classes have been changed too:

new MongoClient();  //Old Classnew MongoDB\Driver\Manager(); // New Class

Refer - http://php.net/manual/en/set.mongodb.php