0

I have Xammp installed in my machine, and I have installed MongoDB. I am able to see the MongoDB module installed in phpinfo, but when I tried to connect MongoDB through a PHP script, it gives me following error:

Fatal Error : Failed to connect to: localhost:27017: No connection could be made because the target machine actively refused it.

Here is my PHP code:

<?php
try{
$connection = new MongoClient();
var_dump($connection);
} catch(Exception $e){
    echo "<pre>"; print_r($e); echo "</pre>";
    die;
}
?>

PHP Version : 5.4.19
OS : Windows 7, 32 -bit system
Mongo DB Version : 1.4.5

halfer
  • 19,824
  • 17
  • 99
  • 186
Ronak Shah
  • 450
  • 2
  • 9
  • 23

1 Answers1

1

What you see in phpinfo() is just the availability of MongoDB PHP extension, not the status of MongoDB server.

What the error most probably means is that your server is not running, or not listening on port 27017.

Check MongoDB server logs for any error messages.

Michael Spector
  • 36,723
  • 6
  • 60
  • 88