How to use XAMPP with MongoDB and the MongoDB PHP driver

This is the MongoDB Logo

This short tutorial will describe how to use MongoDB together with XAMPP.

It is tested with the following environment:

1. In the first step we have to download XAMPP and MongoDB (together with the PHP driver for MongoDB).

2. Create the directory datadb on your c drive (–> c:\datadb).

3. Unpack the MongoDB zip file to a disired destination

4. Install XAMPP (do not install MySQL as a service)

5.  Go into your XAMPP directory (something like xampp\php) and add the following line to the file php.ini

extension=php_mongo.dll

6. Unzip the php_mongo.dll to the follwing directory: xampp\php\ext

7. Start the Apache with the XAMPP Control Center

8. Start MongoDB server ( MongoDBDirectory\bin\mongod.exe )

That’s it. If you want to try if everything works you can use try out the following PHP scriptlet:

test.php

<?php
 $m = new Mongo();
 $db = $m->testDB;
  $collection = $db->users;

  // Insert two documents (objects) into the db
  $collection->insert(array("username" => "John", "email" =>
                     "john@doe.de", "password" => "jd"));
  $collection->insert(array("username" => "Jane", "email" =>
                     "jane@doe.de", "password" => "jd"));

  // Display the documents inside the users collection
  $obj = $collection->find();
  foreach ($obj as $user) {
    var_dump($user);
    echo "</br>";
  }
?>

Put test.php in the htdocs directory of XAMPP (e.g. xampp\htdocts\mongoTest\test.php) and call it with your browser:

http://localhost/mongoTest/test.php

Perhaps this tutorial is useful for someone.

4 Responses to this post.

  1. [...] Steinberg hat hierzu eine Anleitung zur Installation von MongoDB mit XAMPP [...]

  2. Posted by Document-oriented Datenbanken | Imho on 11.03.10 at 19:12

    [...] man sich seine MongoDB unter Windows mit XAMPP installiert, wird im mBlog von Marvin Steinberg erklärt. Sind tatsächlich nur 8 Schritte. Also eine einfache [...]

  3. Posted by michal on 11.03.10 at 19:12

    Hi,
    I install xampp- step 4.
    But i do not have XAMPPDirectoryphp under xampp – step 5.
    And even if i had, i did not undersdand to which file i should add the following :

    extension=php_mongo.dll
    

    ?

    Thanks
    Michal

  4. Posted by marvin on 11.03.10 at 19:12

    Hi Michal,

    you have to insert the line into the php.ini .
    I updated the tutorial, have another look.

    Marvin

Respond to this post

*