Previously “Mongo” was the extension used for MongoDB (Legacy) driver for PHP. Now that is depreciated. Now “MongoDB” Pecl extension is used instead of “Mongo” Pecl extension. And MongoDB Driver is PHP’s official driver for MongoDB. Here is detail of this driver on php.net: http://php.net/manual/en/set.mongodb.php . It supports PHP as well as HHVM.
To have this MongoDB driver working, you need to install pecl “MongoDB” extension.
To install PHP MongoDB on Linux, follow below mentioned steps:
- Run this command:
sudo pecl install mongodb
- Then add following line to php.ini
extension=mongodb.so
- Then you need to restart your apache or nginx . If you are using apache then use following command to reload it.
-
service apache2 reload
To test your installation try instantiating “MongoDB\Driver\Client” by using code similar to this one:
$client = new MongoDB\Driver\Client("mongodb://localhost:27017");
If it says that MongoDB\Driver\Client not found or not defined then there is chance that MongoDB driver is not properly installed. However parameters to this constructor can be changed depends on your MongoDB URL.
In case of any problem, feel free to let me know in comments section.
MongoDB\Driver\Client is deprecated and WILL CAUSE AN ERROR even if the mongodb extension is installed correctly.
thanks brother haafiz
i am using ubuntu16 + php7 + nginx
when i run command ” sudo pecl install mongodb ”
i get this Error:
running: phpize
sh: 1: phpize: not found
ERROR: `phpize’ failed
i installed php-dev package and every thing worked well