title: Uncaught exception 'MongoConnectionException'
body: <pre><code>Fatal error: Uncaught exception 'MongoConnectionException' with message 
  'Failed to connect to: localhost:27017: Permission denied' in 
  /var/www/html/test.php:8 Stack trace: #0 /var/www/html/test.php(8): 
  MongoClient-&gt;__construct() #1 {main} thrown in /var/www/html/test.php 
  on line 8
  </code></pre>
  
  <p>Hi Mongo experts...</p>
  
  <p>I am a developer wanting to try out MongoDB. So installed centoOS 6.5 64bit in a test machine (Dell E520 Intel Dual Core 4GB Ram), installed PHP (Apache was already present).</p>
  
  <p>Then installed MongoDB (yum install mongo-10gen mongo-10gen-server), then installed "pecl install mongo" (install ok: channel://pecl.php.net/mongo-1.4.5), added extension=mongo.so to php.ini. </p>
  
  <p>To install pecl, I installed few other things like C++ compiler &amp; php-pear. php5-dev &amp; php5-cli was not available in yum so installed php-devel &amp; php-cli (installed versions are php-devel-5.3.3-27.el6_5.x86_64 &amp; php-cli-5.3.3-27.el6_5.x86_64</p>
  
  <p>I turned off iptables firewall. Ran mongo --host localhost:27017 from shell &amp; connected without problems</p>
  
  <pre><code>[root@localhost ~]# mongo --host localhost:27017
  MongoDB shell version: 2.4.8
  connecting to: localhost:27017/test
  &gt; 
  </code></pre>
  
  <p>These are the contents of test.php</p>
  
  <pre><code>&lt;?php
  ini_set('display_errors',1);
  ini_set('display_startup_errors',1);
  error_reporting(-1);
  
  // connect
  $m = new MongoClient();
  //$m = new MongoClient("mongodb://localhost:27017");
  
  // select a database
  $db = $m-&gt;comedy;
  
  // select a collection (analogous to a relational database's table)
  $collection = $db-&gt;cartoons;
  
  // add a record
  $document = array( "title" =&gt; "Calvin and Hobbes", "author" =&gt; "Bill Watterson" );
  $collection-&gt;insert($document);
  
  // add another record, with a different "shape"
  $document = array( "title" =&gt; "XKCD", "online" =&gt; true );
  $collection-&gt;insert($document);
  
  // find everything in the collection
  $cursor = $collection-&gt;find();
  
  // iterate through the results
  foreach ($cursor as $document) {
      echo $document["title"] . "\n";
  }
  ?&gt;
  </code></pre>
  
  <p>As you can see I have tried both 
  $m = new MongoClient(); &amp; $m = new MongoClient("mongodb://localhost:27017");</p>
  
  <p>But I am getting the same error. Where am I going wrong?</p>