I'm using linux (Ubuntu 15.04) for a web project. Somehow I managed to install 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:
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. MongoDb version is 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. I can use the db. But PHP won't connect to the database.
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. I hate linux and I will go back to windows if can't find a solution.
Moppo's answer solves the problem:
Problem solved: apparenty it was caused by a problem/bug in the PHP mongo driver version 1.4.
I've upgraded the driver to version 1.6 with:
pecl upgrade mongo
and now the authentication works.
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.