doushi8186 2014-02-24 00:19
浏览 77
已采纳

无法使用PHP和NGINX连接到MongoDB

I can not connect to MongoDb using PHP, the error I am getting is

Failed to connect to: 127.0.0.1:27017: Authentication failed on database 'abc' with username 'admin': auth fails

The code that I use to connect is:

<?php
try {
    $server = new Mongo("mongodb://admin:admin@127.0.0.1:27017/abc");
} catch (Exception $e) {
    echo $e->getMessage();  
}
?>

I have also installed RockMongo which can connect to the database fine.

The control panel that I am using is: ispconfig.org, I have added port 27017 to the firewall via the control panel so it's passing trough.

  • 写回答

1条回答 默认 最新

  • dongzhi6382 2014-02-24 08:27
    关注

    So in a nutshell you seem to confusing the default credentials for you RockMongo UI with credentials to connect to MongoDB.

    By default on installation, MongoDB has no Authentication turned on. You can configure authentication if you so desire, and even add that configuration to your Rockmongo Setup so that it can work on a privileged user.

    All details are in the links provided.

    For now just connect as follows:

    mongodb://<hostname>/<database>
    

    Provided you have access from your or another machine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料