Open In App

How to Install MongoDB Driver in PHP?

Last Updated : 05 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • MongoDB can store documents in a flexible mode. So, these document’s data structures can be changed further in the future.
  • MongoDB is distributed in nature. 
  • As MongoDB is open-source in nature, it is free to use & easy to install.

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.

Downloading-the-Drivers

 

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.

Choose-the-driver

 

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.

Select-the-dll-file

 

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

Pasting-the-dll-file

 

Step 6: Now open the php.ini file.

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

Adding-the-driver

 

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




<?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.

Final-output

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads