简体   繁体   中英

Connect to EC2 AWS mongoDB server using PHP from Godaddy

So I have setup a Bitnami EC2 mongoDB server. It is running, I can connect to it locally and I have inserted some documents and I am able to see my database and the documents using MongoDB Compass (through SSH tunnel). In the security group of my EC2 instance I allow all traffic from all ports (for test purposes). I have commented out also the bind_ip from the mongod.config file. However when running the following code

<?php
$key = '1234';
$m = new MongoClient("mongodb://xx.xxx.xx.xxx", array("username" => $bitnami", 
"password" => $key));
?>

I get the following error "Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: xx.xxx.xx.xxx:27017: Connection refused'"

I have searched for possible answers and asked a similar question in stackoverflow before but it solved my problem only partially. I know the MongoClient command is deprecated but using the MongoDB\\Driver\\Manager I also cannot connect and no error message is shown. I hope somebody can help me with this, thanks in advance!

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.

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