[英]PHP MongoDB Auth Fails
I'm using linux (Ubuntu 15.04) for a web project. 我正在将linux(Ubuntu 15.04)用于一个Web项目。 Somehow I managed to install mongodb.
我以某种方式设法安装了mongodb。 I have created a user and I can connect to the database via terminal.
我已经创建了一个用户,并且可以通过终端连接到数据库。
But when I try to connect to the DB via PHP script it gives this error: 但是,当我尝试通过PHP脚本连接到数据库时,出现此错误:
Failed to connect to: 127.0.0.1:27017: Authentication failed on database 'user1' with username 'user1': auth failed
Mongo Driver version is 1.5.7. Mongo驱动程序版本为1.5.7。 MongoDb version is 3.0.4
MongoDb版本是3.0.4
Also when I connect to the database via terminal it gives me these warnings: 另外,当我通过终端连接到数据库时,它也会显示以下警告:
MongoDB shell version: 3.0.4
connecting to: test
Server has startup warnings:
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten]
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten]
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten]
But it accepts db.auth(username, password) and auths successfully. 但是它成功接受db.auth(用户名,密码)并进行身份验证。 I can use the db.
我可以使用数据库。 But PHP won't connect to the database.
但是PHP无法连接到数据库。
Please help. 请帮忙。 I am trying to find the solution but everybody says something different and no solution works.
我正在尝试找到解决方案,但每个人都说些不同,没有解决方案。 I am spending hours to just to make it work under linux.
我花几个小时只是为了使其在Linux下工作。 I hate linux and I will go back to windows if can't find a solution.
我讨厌linux,如果找不到解决方案,我将回到Windows。
Moppo's answer solves the problem: Moppo的答案解决了这个问题:
Problem solved: apparenty it was caused by a problem/bug in the PHP mongo driver version 1.4.
解决的问题:显然是由PHP mongo驱动程序1.4版中的问题/错误引起的。
I've upgraded the driver to version 1.6 with:
我已使用以下命令将驱动程序升级到1.6版:
pecl upgrade mongo
and now the authentication works.
现在身份验证有效。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.