≡ Menu

How to Configure MongoDB with PHP for XAMPP on Windows

XAMPP is an open source, easy to use and easy to install stack that contains Apache webserver, MySQL database, PHP compiler and Perl.

MongoDB is one of the most widely NoSQL database in market today. We often end up in a situation where we might find it useful to set up mongodb also along with PHP in the XAMPP stack.

Since mongoDB is not an integral part of this stack, we have to set it up manually as the XAMPP installer is not going to take care of it for you.

Follow the steps below to configure MongoDB for the XAMPP stack.

1. Install and Configure XAMPP

First, you should install the XAMPP stack. Download and install the XAMPP stack from Apache friends project.

Also, keep in mind that you can also install XAMPP on Linux as we discussed earlier.

After the install, start your Apache server from XAMPP controls and create a simple PHP file to get the detailed info about the PHP running with your stack. Just copy paste the below lines to a test.php file in the htdocs folder and execute it to see the output.

<?php
 echo phpinfo();
?>

As highlighted in the screenshot below, you will find the PHP version, Architecture, Compiler in use and can see whether thread safety is enabled or not.
XAMPP phpinfo

2. Download PHP Mongo Driver

From this PHP Mongo Driver download page, download the appropriate file that matches the PHP version, Architecture, Compiler in use and Thread Safety from the XAMPP that is installed on your system.

3. Copy PHP Mongo DDL to EXT Directory

After you unzip the php monngo driver zip file, copy and paste the “.dll” file to the folder “C:\xampp\php\ext”( Assuming that xampp is installed on C drive).

This ext folder all the “.dll” files of all the extensions that are installed. XAMPP loads the driver files for the extensions from this folder.

After copying the file over here, rename the “.dll” file to “php_mongo.dll” for simplicity.

4. Add Extension to php.ini

Next, open the “php.ini” file from the path “C:\xampp\php” (again, assuming that xampp is installed on C drive), and edit this file to add the name of the “.dll” file as an extension.

Add the following line to the php.ini file.

extension=php_mongo.dll

Later, if you like, you can also disable this extension by adding a semicolon before the line so that it becomes as shown below:

;extension=php_mongo.dll

5. Modify the PATH Variable

Go to control panel, and open the system settings to add the “Environment Variable”.

Add the path of the xampp php installation ( C:\xampp\php ) to the path variable, if it is not present already. This ensures that the newly added “.dll” file is loaded when xampp is started.

XAMPP Add to PATH

6. Restart Apache and Verify

Finally, restart the Apache server from the XAMPP control panel.

If everything is configured properly, xampp should not throw any error messages while starting apache. You can also check the loaded extension by going through the first step and looking into the php information.

You will be able to see the loaded extension information on the page as shown below.

XAMPP phpinfo with Mongo Support
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Bruno Buiret October 22, 2015, 2:12 pm

    Thank you for this! I hadn’t been able to install the Mongo extension on WAMP and now I succeeded =)

  • Deepak October 23, 2015, 10:39 am

    God article. There is typo in #3 it’s dll not ddl

  • Marcos October 29, 2015, 11:37 pm

    Yes the title says DDL on step #3

  • Van March 5, 2016, 4:34 am

    Hi, I’m trying this step with PHP version 7.0.3, compiler MSVC14, architecture x86. I downloaded the php_mongo-1.6.8.zip and unzipped them. May I know which .dll am I supposed to copy over? I copied one and renamed it as in the article. When it didn’t work, I repeated it with a different .dll file but I’m still having fatal error being thrown for mongo. Kindly advise.

  • Darshan Kothiya April 25, 2016, 10:16 pm

    Thankyou so much its realy helpfull and work very fine

  • Thank u April 26, 2016, 3:50 am

    Hi you are awesome…solved my problem with your simple steps!

  • Bhawana June 28, 2016, 4:56 am

    The article was very helpful to me except that I could not find the correct dll to be copied in the ext folder under php.
    Then my colleague helped me in identifying the correct file from php.net and it worked.

  • Nikshay August 24, 2016, 2:49 pm

    Thanks a ton!!! This worked perfectly.

  • amit January 16, 2017, 3:34 pm

    But what after that I’m gettingvsome exception error

  • John April 15, 2017, 6:14 pm

    Good article, more info on which dll to use here:
    https://docs.mongodb.com/ecosystem/drivers/php/
    In my case, the download was:
    https://pecl.php.net/package/mongodb/1.2.8/windows