
MongoDB is an open source database mangaement system that supports handling of huge data either in structured or un-structured formats. Using a database only with its commands in shell does help us to get working with any realtime applications. Database systems needs to get connected with any programming language to facilitate development of realtime applications.
So let’s now jump on to the connectivity of MongoDB with PHP.
Requirements:
1. OS Version Windows 7 or later
2. XAMPP with PHP(better with 7.1 or latter)
(Installation Tutorial : https://www.apachefriends.org/download.html )
3. MongoDB Latest Version
(Installtion Tutorial : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/ )
Before you start continuing with this tutorial, ensure that you have MongoDB installed properly and you are able to access databases in MongoDB using the Mongo Shell.
Step 1: Check your PHP Version
The first step you should do is to find out the version of PHP you have installed. Start Apache Server in XAMPP and click on Admin . A page will open automatically in browser and you can find the PHP version in that page.

Step 2: Download the PHP MongoDB Driver
In order to access Mongo database with PHP, you first need the driver that connects MongoDB Engine with PHP.
The driver can be downloaded from the following URL:
http://pecl.php.net/package/mongodb/1.6.0/windows
Download the driver equivalent to your version of Windows (32 bit 0r 64 bit) and choose thread safe version because XAMPP has Thread Safe Version of PHP.
After downloading the driver, extarct the zip file and copy the php_mongodb.dll file. Now navigate to your Xampp Installation Directory and go into php directory and there will be directory named ext and paste your file there.
i.e. (XAMPP\php\ext)
Step 3: Adding extension to php configuration file:
The next step is to add a dynamic extension mapping to MongoDB Driver file that we added above. So navigate to XAMPP\php directory and there will be a configuration file named php.ini

Open the file in any text editor and add the following line below the Dyanmic Extensions that already exists in the file.extension=php_mongodb.dll
(Do not add semicolon(;) infront of this line)
After adding the extension, restart your Apache Server in XAMPP to make the changes to take place.
Step 4: Checking the Installation of Drive:
Now in order to verify whether the driver has been installed successfully or not , Click on the Admin Button near to Apache in XAMPP which will open up a page in browser.
In the page that opened up, click on PHPInfo and search for a tabular column with title mongodb which will list all the driver details.
If you did not find such a table then your configuration has not worked suceesfully.Try rechecking the steps you followed once again.
You can also check the error details in the log file which open by click the log button near Apache in XAMPP and selecting Apache(error.log)
Please feel free to share your valuable comments and comment me if you face any errors .
To get information on performing CRUD operations with PHP in MongoDB ,please have a look into my post on CRUD Operations in MongoDB with PHP
Let’s meet in the next interesting post.
One Comment Add yours