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.
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.
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.
Comments on this entry are closed.
Thank you for this! I hadn’t been able to install the Mongo extension on WAMP and now I succeeded =)
God article. There is typo in #3 it’s dll not ddl
Yes the title says DDL on step #3
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.
Thankyou so much its realy helpfull and work very fine
Hi you are awesome…solved my problem with your simple steps!
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.
Thanks a ton!!! This worked perfectly.
But what after that I’m gettingvsome exception error
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