How To MongoDB – PHP Connect on XAMPP in Windows 7

Steps:

  1. Download drivers – mongodb.org – Screen prints  1,2, 3 and 4
  2. Extract driver download zip – please note that the _64 ones don’t work with XAMPP. Screen Print 5 
  3. Check phpinfo() to verify our PHP version along with the build info (Thread Safe vs Non-Thread Safe and Visual C++ compile – recent XAMPP is VC9. Screen Print 6
  4. Place chosen driver in php extensions directory, make a copy and rename to php_mongo.dll. My directory is c:\xampp\php\ext (I’m using the default). Screen Print 7
  5. Edit php.ini - add this line to php.ini – extension=php_mongo.dll. Screen Print 8
  6. stop and start apache to use updated php.ini. Screen Print 9
  7. Verify phpinfo() now includes Mongo section. Screen Print 10
  8. Run the mongo test – show the error with out MongoD running. Screen Print 11
  9. Start mongod. Screen Print 12
  10. Run test php script (code below). Screen Print 13
  11. View Document in Mongo Shell. Screen Print 14
  12. MongoDBPHPVerify.php code below
  13. Video Tutorial embedded below
  14. Enjoy your PHP connection to MongoDB.

Screen Print 1 - MongoDB.org - we’re going to click on the Drivers link:

Screen Print 2 – PHP Language Center

Screen Print 3 – Click on the github download link

Screen Print 4 – Select the most recent stable version (skipped RC – “Release Candidate”).

Screen Print 5 – Unzip the download to see available drivers

Screen Print 6 – View phpinfo() for your specific PHP version, ts or nts (thread safe) and Visual C++ compile info – mine is PHP version 5.4.7, TS and VC9. We use these values to choose the correct .dll

Screen Print 7 – Place, copy and rename driver in ext directory – “php_mongo.dll”

Screen Print 8 – add the php_mongo.dll extension to php.ini

 Screen Print 9 – XAMPP control panel – Bounce the Apache server to allow the php.ini changes to take effect

 Screen Print 10 – Verify Mongo extension in phpinfo()

 Screen Print 12 – Error when attempt to run without active MongoD (mongo daemon/server)

Screen Print 12 – Start a MongoD. I use a .bat file called startmongo.bat with 1 line to start mongod and specify a non-default data directory (d:\DevMongoDB\MongoData).

 Screen Print 13 – Run test connect php script (code is below)

Screen Print 14 – view test document in Mongo Shell

Here’s the Test PHP script to verify the connection:

 

Here’s the Video:

One thought on “How To MongoDB – PHP Connect on XAMPP in Windows 7

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Powered by sweet Captcha