简体   繁体   English

MongoDB + PHP:错误“无法连接到 127.0.0.1:27017”

[英]MongoDB + PHP: Error “Failed to connect to 127.0.0.1:27017”

I have running a EC2 instance with MongoDB and some.php files to deploy a little webpage.我已经运行了一个带有 MongoDB 和 some.php 文件的 EC2 实例来部署一个小网页。 PHP shows productos taken from MongoDB. PHP 显示取自 MongoDB 的产品。

<?php
include_once("header.php");
require 'vendor/autoload.php';
$uri="mongodb://localhost";
$client=new MongoDB\Client($uri);

$collection = $client->tienda->categorias->find();
$categorias=array();

When I created DB it was no problem.当我创建数据库时,这没问题。 After a new login to EC2 webpage doesn't show anything from DB.重新登录 EC2 网页后,DB 中没有显示任何内容。 When I try to check DB this error returns:当我尝试检查数据库时,此错误返回:

> use tienda
> show collections
2020-05-13T17:29:29.612+0000 I NETWORK  [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2020-05-13T17:29:29.612+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2020-05-13T17:29:29.612+0000 I NETWORK  [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
2020-05-13T17:29:29.612+0000 E QUERY    [thread1] Error: socket exception [CONNECT_ERROR] for couldn't connect to server 127.0.0.1:27017, connection attempt failed :
runClientFunctionWithRetries@src/mongo/shell/session.js:346:31
runCommand@src/mongo/shell/session.js:412:25
DB.prototype._runCommandImpl@src/mongo/shell/db.js:145:16
DB.prototype.runCommand@src/mongo/shell/db.js:161:20
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:930:19
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:953:19
DB.prototype.getCollectionNames@src/mongo/shell/db.js:964:16
shellHelper.show@src/mongo/shell/utils.js:809:9
shellHelper@src/mongo/shell/utils.js:706:15
@(shellhelp2):1:1
2020-05-13T17:24:05.117+0000 I NETWORK  [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2020-05-13T17:24:05.117+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2020-05-13T17:24:05.117+0000 I NETWORK  [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed

After some google hours the only way I found to keep DB working is running on a new tab经过一些谷歌小时后,我发现保持数据库工作的唯一方法是在新标签上运行

$ mongod

Once I close this tab, DB stops to work and webpay stops to display products.关闭此选项卡后,DB 停止工作,webpay 停止显示产品。 Is there any way to fix this?有没有什么办法解决这一问题? I'm new to MongoDB btw.我是 MongoDB 的新手。

You can run the MongoDB process as a daemon您可以将 MongoDB 进程作为守护进程运行

mongod --fork --logpath /var/log/mongodb/mongod.log

Where logpath is where logs will be saved. logpath 是保存日志的位置。

Documentation: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/文档: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/

暂无
暂无

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

相关问题 “致命错误:未捕获的异常&#39;MongoConnectionException&#39;,消息为&#39;无法连接至:/tmp/mongodb-27017.sock:0:连接被拒绝&#39;” - “Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: /tmp/mongodb-27017.sock:0: Connection refused''” 无法连接到MongoDB:无法连接到:333.33.333.333:27017:连接被拒绝 - Unable to connect to MongoDB: Failed to connect to: 333.33.333.333:27017: Connection refused php无法连接到mongodb套接字 - php failed to connect to mongodb socket 无法连接到:localhost:27017:连接被拒绝 - Failed to connect to: localhost:27017: Connection refused 身份验证失败:分片的MongoDB上的用户文档中缺少MONGODB-CR凭据:无法连接至:queryrouter0.example.com:27017: - AuthenticationFailed: MONGODB-CR credentials missing in the user document on sharded MongoDB: Failed to connect to: queryrouter0.example.com:27017: cURL 错误 [0]:无法连接到 127.0.0.1 端口 8545:连接被拒绝 - cURL error [0]: Failed to connect to 127.0.0.1 port 8545: Connection refused 无法连接到数据库:无法连接到:localhost:27017:连接被拒绝 - Unable to connect to Database: Failed to connect to: localhost:27017: Connection refused Codeigniter错误无法连接到MongoDB:连接失败:身份验证失败 - Codeigniter error Unable to connect to MongoDB: Failed to connect: auth failed 消息“未能连接到:localhost:27017”的未捕获异常“ MongoConnectionException” - Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017 php错误:SMTP connect(); 失败 - php Error:SMTP connect(); failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM