Himanshu Joshi
Himanshu Joshi

Reputation: 79

Unable to connect to MongoDB hosted on a different server - PHP

I have created two AWS instances and have allotted two different Elastic IPs to them. One instance is used for the database server (hosted in MongoDB) while the other is for hosting the website.

I am unable to connect to the server through my PHP code. My code looks as under:

try{
    $connection = new Mongo('mongodb://107.21.230.121:27017');
}
    catch (MongoConnectionException $exception)
{
    print_r($exception->getMessage());
}   

When I run this code on my website, I get the following error:

"Failed to connect to: 107.21.230.121:27017: Timed out after 0 ms."

I have checked the server on which MongoDB is running. Using Mongo shell, I was also able to create some collections and documents.

Have tried all sorts of tactics without success. Can somebody suggest me where can I be wrong in the set up?

Upvotes: 2

Views: 1904

Answers (1)

Nick
Nick

Reputation: 1554

Judging from a quick and dirty nmap scan of your instance, it looks like you've not opened up the port (27017) in your Security Groups. This will need to be done on port servers.

Upvotes: 2

Related Questions