Open In App

How to Install MongoDB Driver in PHP?

MongoDB is a database & it verifies the document databases. It is widely used for its flexibility & scalability. MongoDB provides a cloud & server-based database management system. Also, it provides some extra plugins to use MongoDB in different aspects also. It provides a PHP driver plugin that enables MongoDB to work with PHP server providers. For downloading PHP drivers of MongoDB, the main requirement is that any type of server like Wamp or Xampp should be installed on the machine previously. Otherwise, it will not work further. The Xampp Apache should be configured & run before in hand.

Features:



Installing MongoDB PHP Driver

Follow the following steps to install MongoDB PHP Drivers:

Step 1: For downloading PHP Drivers, browse the official website using any browser. There are many versions of PHP drivers of MongoDB that can be found. It is advisable not to go for alpha or beta versions. Stable versions should be used. As alpha or beta versions are those which are still under verification. According to individual machine configuration, the proper version should be installed. Here, according to this machine, the proper version will be 1.7.4, if any individual wants to install some older version also, there is no problem with it. Click on the DLL of the proper version for the next step.



 

Step 2: Then according to PHP installed in the machine previously, the proper file should be installed. Like in this case, according to PHP versions & machine configuration following Driver is going to install. It will install a .zip file. That needs to be extracted.

 

Step 3: After extraction of the installed .zip file, there will be a .dll file. That file needs to be copied. It is going to be pasted in the Xampp server.

 

Step 4: Then the below path should be followed. In the ext folder, the copied php_mongodb.dll file should be pasted. 

C:\xampp\php\ext

 

Step 6: Now open the php.ini file.

 

Step 7: Now in the php.ini file search find the series of extensions and add the following file in it with a semicolon.

extension = php_mongo.dll

 

Step 5: Now restart the xampp server to see the changes. Now we run a simple code to see if the driver is properly working or not. 




<?php
    $n = new Mongo();
?>

When we run this code we will get the following output. If we get any error then that means our MongoDB driver is not installed properly.

 

Article Tags :