How to Set Up MongoDB with WAMP on Windows (and Use It from PHP)

WAMP gives you Apache, PHP and MySQL on Windows in one install. It doesn’t include MongoDB, so if a project needs a document database next to MySQL, you add it yourself. I first wrote this guide in 2017, when the setup meant hand-made folders and config files inside the WAMP directory. Today it’s simpler: install MongoDB as a normal Windows service, then connect PHP to it with the official extension and library.

This guide covers all four steps: installing MongoDB, checking it runs, adding the PHP extension to WAMP, and connecting from a PHP script.

What you need

  • WampServer installed and working (64-bit, with PHP 8.1 or newer selected).
  • Admin rights on your Windows machine.
  • Composer installed (for the PHP library).

Step 1: Install MongoDB Community Server

  1. Download MongoDB Community Server for Windows (the .msi package) from the official MongoDB download page.
  2. Run the installer and choose Complete.
  3. On the service screen, keep Install MongoD as a Service ticked and Run service as Network Service user. The default data folder (C:\Program Files\MongoDB\Server\<version>\data) is fine.
  4. Optionally untick MongoDB Compass if you don’t want the GUI. You can install it later.

Running MongoDB as a service means it starts with Windows, just like WAMP’s MySQL. You no longer need the old approach of a mongodb.conf file inside wamp64\bin.

Step 2: Check MongoDB is running

The old mongo shell is no longer bundled, so install mongosh (the MongoDB Shell) from the MongoDB downloads page. Then open a terminal and run:

mongosh

If you see a prompt like test>, MongoDB is running on the default port, 27017. Try a quick insert:

use demo
db.notes.insertOne({ title: "Hello from WAMP" })
db.notes.find()

If mongosh can’t connect, open Services (services.msc), find MongoDB Server, and make sure it’s running.

Step 3: Add the MongoDB extension to WAMP’s PHP

PHP talks to MongoDB through the mongodb extension. The DLL must match your PHP setup exactly, or Apache won’t load it.

  1. In WAMP, left-click the tray icon → PHP → check your version (for example 8.3.x).
  2. Run php -i in a terminal (using WAMP’s PHP) and note two things: Thread Safety (WAMP’s Apache PHP is usually enabled, which means TS) and Architecture (x64).
  3. Download the matching Windows build of the mongodb extension from its PECL page (pecl.php.net/package/mongodb). Choose the zip for your PHP version, TS, and x64.
  4. Copy php_mongodb.dll into wamp64\bin\php\php<version>\ext\.
  5. Add this line to the php.ini that Apache uses (tray icon → PHP → php.ini):
extension=mongodb
  1. Restart all WAMP services. Open localhost → phpinfo() and search for mongodb. If the section appears, the extension is loaded.

A common trap: WAMP has two php.ini files, one for Apache and one for the command line. Add the line to both if you also run PHP scripts from the terminal.

Step 4: Connect from PHP

Install the official library in your project folder:

composer require mongodb/mongodb

Then create test-mongo.php:

<?php
require __DIR__ . '/vendor/autoload.php';

$client = new MongoDB\Client('mongodb://127.0.0.1:27017');
$notes  = $client->demo->notes;

$notes->insertOne(['title' => 'Inserted from PHP', 'created' => new MongoDB\BSON\UTCDateTime()]);

foreach ($notes->find() as $note) {
    echo $note['title'], PHP_EOL;
}

Open it in the browser through WAMP. You should see both notes: the one from mongosh and the one from PHP.

Troubleshooting

  • “Class MongoDB\Client not found”: you didn’t run composer require, or you didn’t include vendor/autoload.php.
  • “Class MongoDB\Driver\Manager not found”: the extension isn’t loaded. Check the DLL matches your PHP version, TS/NTS and x64, and that you edited the right php.ini.
  • Apache won’t start after adding the DLL: the DLL doesn’t match. Remove the extension=mongodb line, restart, and download the correct build.
  • Connection refused: the MongoDB service isn’t running. Start it in services.msc.

MySQL or MongoDB for your project?

Running both in WAMP is easy, but most PHP projects only need one. Use MySQL when your data is relational (orders, users, invoices) and MongoDB when records vary in shape or nest deeply. I compare the options in Choosing the Right Database for Your Website or Application.

Frequently Asked Questions

Does WAMP include MongoDB?

No. WampServer bundles Apache, PHP, MySQL and MariaDB. You install MongoDB separately and connect PHP to it with the mongodb extension.

Which PHP extension do I need for MongoDB?

The mongodb extension (php_mongodb.dll on Windows), plus the mongodb/mongodb Composer library. The old mongo extension is discontinued and doesn’t work with PHP 7 or 8.

Should I pick the TS or NTS DLL for WAMP?

Pick whatever phpinfo() shows under Thread Safety. WAMP’s Apache PHP is normally thread safe (TS), and the DLL must also match your PHP version and x64.

Where is the MongoDB shell?

Newer MongoDB versions no longer include the old mongo shell. Install mongosh separately, or use MongoDB Compass.