简体   繁体   English

无法通过PHP连接到MongoDB

[英]Can't connect to MongoDB through PHP

I just wanted to take a look at Mongo-DB. 我只是想看看Mongo-DB。 But i just don't get it running. 但是我只是不让它运行。 I've installed it with PECL and my phpinfo() tells me that the extension is loaded, but when i try to get a connection with 我已经用PECL安装了它,我的phpinfo()告诉我扩展已加载,但是当我尝试与

$mongo = new Mongo();

I get this: 我得到这个:

Fatal error: Uncaught exception 'MongoConnectionException' with message ': Transport endpoint is not connected' 致命错误:消息“:未连接传输终结点”的未捕获异常“ MongoConnectionException”

Anybody have the same Problem? 有人有同样的问题吗? ... Or any Idea on this? ...或对此有任何想法?

Please don't take this the wrong way, but have you actually got the server running? 请不要采取这种错误的方式,但是您实际上已经在运行服务器吗? Only it looks like your error relates to a failure to connect and you've made no mention of the server or where it is located (localhost on the default port for example) 只是看起来您的错误与连接失败有关,并且您没有提及服务器或服务器的位置(例如,默认端口上的localhost)

any server start method, such as "/etc/init.d/mongodb start" or "service start mongodb" will fail, if a stale lock file still exists. 如果仍然存在陈旧的锁定文件,则任何服务器启动方法(例如“ /etc/init.d/mongodb start”或“ service start mongodb”)都将失败。 In Ubuntu/Debian this is /var/lib/mongodb/mongod.lock. 在Ubuntu / Debian中,这是/var/lib/mongodb/mongod.lock。 Look for this and delte it, if it exists and seems to be an old one. 寻找并删除它,如果它存在并且似乎已经很旧了。

check out whether server is running or not.. 检查服务器是否正在运行。

/etc/init.d/mongodb start /etc/init.d/mongodb开始

then go to 然后去

root@kannan-desktop:~# mongo MongoDB shell version: 1.6.3 connecting to: test > root @ kannan-desktop:〜#mongo MongoDB Shell版本:1.6.3连接到:test>

如果是新安装的,请不要忘记更改mongod.conf的IP。

自定义字符串看起来像这样

mongodb://username:password@host:port/database

First Change the Default db path by following command 首先通过以下命令更改默认数据库路径

$ sudo mkdir -p /data/db/ $ sudo mkdir -p / data / db /

$ sudo chown id -u /data/db $ sudo chown id -u / data / db

and then the final command is.. 然后最后的命令是..

$ mongod --journal $ mongod --journal

Do not close terminal until you are working with mongoDB 在使用mongoDB之前,请勿关闭终端

It works for me... 这个对我有用...

只需在您的终端上写mongod就可以了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM