title: Can't authenticate on mongodb with PHP
body: <p><strong>What i've done:</strong></p>
  
  <p>Enabled authentication in <code>/etc/mongod.conf</code> :</p>
  
  <pre><code>auth = true
  </code></pre>
  
  <p>Created the first user from the shell as stated in the <a href="http://docs.mongodb.org/manual/tutorial/enable-authentication/" rel="noreferrer">doc</a> :</p>
  
  <pre><code>db.createUser(
  {
      user: "admin",
      pwd: "admin",
      roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  })
  </code></pre>
  
  <p>Using the <code>admin</code> user, i've created a <code>root</code> user to access mongodb: </p>
  
  <pre><code>db.createUser(
  {
      user: "root",
      pwd: "root",
      roles: [ "root" ]
  })
  </code></pre>
  
  <p>Until this point all works fine, as i can authenticate from the mongo shell with:</p>
  
  <pre><code>mongo --port 27017 -u root -p root  admin
  </code></pre>
  
  <p>and it works perfectly, as i can make all operations in the db.</p>
  
  <p><strong>The problem</strong>: </p>
  
  <p>when i try to authenticate from PHP using the same <code>root</code> user:</p>
  
  <pre><code>$client = new MongoClient("mongodb://root:root@localhost:27017/admin");
  </code></pre>
  
  <p>It gives the error:</p>
  
  <blockquote>
    <p>Failed to connect to: localhost:27017: Authentication failed on database 'admin' with username 'root': auth failed</p>
  </blockquote>
  
  <p>Why can't PHP authenticate on mongodb if authenticating with the same credentials works fine from the mongo shell? </p>
  
  <p><strong>Other notes:</strong></p>
  
  <ul>
  <li>If I disable authentication PHP connects perfectly, and the mongo classes work fine</li>
  <li>I've tried to create different users, but the response is the same</li>
  <li>I am using Mongo 3.0.1, PHP 5.5.9 and Ubuntu 14.04.2 LTS 64bit</li>
  </ul>