I am very eager to start working with PHP 7 however one issue is getting in the way... I primarily use MongoDB for the database, and the problem is that I don't know how to install the MongoDB driver/client for PHP 7.
My current installation is PHP 5.6 and on my Mac and brew install php56-mongo
does the trick.
Can anyone recommend how I can get this working on my Mac or an Ubuntu install?
Thanks in advance and much appreciated!
The official MongoDB Node. js driver allows Node. js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to interact with MongoDB using Promises or via traditional callbacks.
You can add the driver to your application to work with MongoDB in PHP. The MongoDB PHP Driver consists of the two following components: The extension , which provides a low-level API and mainly serves to integrate libmongoc and libbson with PHP.
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.net
pecl install mongodb
echo "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 Class
new MongoDB\Driver\Manager(); // New Class
Refer - http://php.net/manual/en/set.mongodb.php
You can try install mongodb driver with:
sudo apt-get install php-mongodb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With