不能用PHP MongoDB的验证 [英] Can't authenticate on mongodb with PHP

查看:319
本文介绍了不能用PHP MongoDB的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了什么:

已启用身份验证 /etc/mongod.conf

auth = true

从创建如文档规定的外壳的第一个用户:

Created the first user from the shell as stated in the doc :

db.createUser(
{
    user: "admin",
    pwd: "admin",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
})

使用管理​​用户,我创建了一个用户访问MongoDB的:

Using the admin user, i've created a root user to access mongodb:

db.createUser(
{
    user: "root",
    pwd: "root",
    roles: [ "root" ]
})

直到此时一切工作正常,因为我可以从蒙戈外壳采用验证:

Until this point all works fine, as i can authenticate from the mongo shell with:

mongo --port 27017 -u root -p root  admin

和它完美的作品,因为我可以在数据库中进行所有操作。

and it works perfectly, as i can make all operations in the db.

问题

当我尝试使用相同的根从PHP来验证用户:

when i try to authenticate from PHP using the same root user:

$client = new MongoClient("mongodb://root:root@localhost:27017/admin");

它给人的错误:

无法连接到:本地主机:27017:身份验证失败与用户名'根'数据库'管理员':验证失败

Failed to connect to: localhost:27017: Authentication failed on database 'admin' with username 'root': auth failed

为什么不能在PHP MongoDB的验证,如果使用相同的身份验证凭据从蒙戈外壳工作正常?

Why can't PHP authenticate on mongodb if authenticating with the same credentials works fine from the mongo shell?

其他注意事项:


  • 如果我禁用验证PHP连接完美,蒙戈班做工精细

  • 我试图创建不同的用户,但响应是一样的

  • 我使用蒙戈3.0.1,5.5.9 PHP和Ubuntu 14.04.2 LTS 64

推荐答案

问题解决了:apparenty它是由PHP蒙戈驱动程序版本中的问题/错误造成的 1.4

Problem solved: apparenty it was caused by a problem/bug in the PHP mongo driver version 1.4

我已经升级了驱动程序版本 1.6

I've upgraded the driver to version 1.6 with:

pecl upgrade mongo

和现在的认证工作。

这篇关于不能用PHP MongoDB的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆