Learn how to install MongoDB on Windows OS and configure with PHP on XAMPP.
There are a couple of tutorials out there already, but neither of them helped me set everything up 100%. Some of them are missing key explanations, some of them are a bit old. My tutorial presumes you know your way around XAMPP on Windows and you have it installed already.
Here’s how to install MongoDB on your local Windows machine with XAMPP in 5 easy steps:
Step 1. Download mongo driver
To download mongo driver for Windows visit pecl.php.net
Download the latest stable release by clicking on the DLL link. I used the latest stable release at the time, 2017-05-04, version 1.2.9.
On the next page there is a DLL list. It is vital to pick the right version. You need to pick depending on three things:
- the PHP version that is installed with your XAMPP
- Architecture x86 or x64
- Whether Thread Safety is enabled or disabled
Here’s where to find out that information:
- Start XAMPP
- Navigate to the XAMPP dashboard via Internet browser (tipically at http://localhost)
- Click the PHPinfo in the top menu
- There, in the new tab you will see the table with the necessary information. At the top, you will see PHP version, in my case it was 7.0.13
Below that, in the table, you will see list of other information. You need to find the value for the Architecture (x86 or x64) and Thread Safety (enabled or disabled).
Finally, you can choose a proper DLL to download.
In my case, I had:
- PHP version 7.0.13
- Architecture x86
- Thread Safety enabled
When Thread Safety is enabled, you need to download Thread Safe (TS) version. So I downloaded file: 7.0 Thread Safe (TS) x86
Step 2. Unzip downloaded mongo driver version and copy .dll file to XAMPP
After successful download, unzip and find the .dll file. Copy it to ext directory of your XAMPP installation. If you installed XAMPP to C drive, full path to the ext folder would be C:\xampp\php\ext
Step 3. Register mongo .dll file within php.ini
Add following line into php.ini file:
If your .dll file name is different, it’s ok, just make sure you call it like that within php.ini file. For example, if you added a file with a name of php_mongo.dll in the ext folder, you need to put that in the php.ini file.
Step 4. Restart XAMPP and refresh phpinfo.php page
When you restart XAMPP and refresh the phpinfo page, something like this should appear when you CTRL+F and type mongo:
If you don’t see that on your phpinfo page, you did something wrong so try to go back through previous steps.
Step 5. Install MongoDB on Windows
a) Download latest MongoDB server version.
b) Choose custom setup type and install in the C:\mongodb folder.
c) Then create db folder within data folder on the C drive – C:\data\db
d) Start MongoDB by executing the following command in the CMD: C:\mongodb\bin\mongod.exe
That is it, you successfully installed MongoDB on Windows and configured it in XAMPP!
Just in case you need extra help with step 5, here is the entire process explained with images.
Step 6. Download and install RoboMongo
As an extra step I would recommend installing MongoDB management tool, such as RoboMongo, (it’s called Robo 3T now) to easily manage MongoDB on your machine. Just create connection and you are set to go.
Conclusion and additional resources
Hope you found this tutorial useful in the process of installing and configuring MongoDB on your Windows machine with XAMPP.
For the next step, I recommend checking out the following MongoDB online courses on Pluralsight:
These fantastic courses by Nuri Halperin helped me to learn a lot more about MongoDB.