Adding mongodb extension for php 5.6 (XAMPP)

14,598

Solution 1

I installed mongo extension with following steps:

Without further configuration, I see mongo extension in command line (C:\xampp\php\php.exe -i | findstr mongo) but Apache complains about missing libsasl.dll and mongo is missing in http://localhost/dashboard/phpinfo.php. Ok, what next?

  • Copy C:\xampp\php\libsasl.dll to C:\xampp\apache\bin\, restart Apache and enjoy.

This howto worked for me well. I hope it will help to resolve your issue.

Solution 2

Follow below steps to make Mongo work for PHP-5.6

  1. goto https://pecl.php.net/package/mongo/1.6.14/windows
  2. download php_mongo-1.6.14-5.6-ts-vc11-x86.zip
  3. extract the zip file and copy php_mongo.dll
  4. open PHP ext directory and paste the dll file
  5. add the following line to your php.ini file
    extension=php_mongo.dll
  6. restrat apache and test with below php code

// connect to mongodb

echo extension_loaded("mongo") ? "loaded\n" : "not loaded\n";

$m = new MongoClient("mongodb://127.0.0.1:27017");

echo "Connection to database successfully";

// select a database

$db = $m->testdb;   // where testdb is already existing Database

echo "Database testdb selected";

Note : Check the "mongo" module is loaded or mot using phpinfo()

Solution 3

In your php.ini file, uncomment this configuration, and restart your Apache Server:

; extension_dir = "ext"

If it doesn't work, try to put an absolute path to your extension directory, where php_mongo-1.6.8-5.6-vc11.dll reside.

UPDATE

I have found this information in PHP_OFFICIAL_WEBSITE
I think you should also add libsasl.dll to your PATH environment variable

Share:
14,598

Related videos on Youtube

dhpratik
Author by

dhpratik

Work is fun. Working as a development enthusiast since 2013. I love to work at top speed and don't compromise anything for it. Open to Work as a freelancer.

Updated on June 26, 2022

Comments

  • dhpratik
    dhpratik almost 2 years

    I have read few post here on solving my issue but neither works for php-5.6.

    I downloaded php_mongo-1.6.8.zip and php_mongo-1.6.7.zip and tried all the .dll extensions and all of them gives one or the other error.

    Error message:

    1. PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_mongo-1.6.8-5.6-vc11-x86_64.dll' - %1 is not a valid Win32 application.

      in Unknown on line 0

    2. PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_mongo-1.6.8-5.6-vc11.dll' - The specified module could not be found.

      in Unknown on line 0

    P.S.: I am using XAMPP for my environment.

  • dhpratik
    dhpratik over 8 years
    thanks for solving my problem, it worked fine.my bounty expired, if u have any idea on how to revive the bounty please inform me.
  • Pascut
    Pascut over 8 years
    For all the haters who downvote - please also add a comment saying what is wrong in my answer. Thanks :)
  • Mago Maverick
    Mago Maverick over 3 years
    I didn't down-vote your answer, but noticed your link does not work.
  • Pascut
    Pascut over 3 years
    Unfortunately the link is not working anymore, but it worked well when I shared it.