Timeout while connecting to MongoDB database with mongo php ext under Ubuntu 12.04 and php 5.6
I'm using
- latest Apache 2.4
- Ubuntu 12.04
- php 5.6 with mongo ext Version 1.6.14
- MongoDB v3.4 running in an lxc container
And the problem is when I connect to the mongo database.
I'm using this connection string:
mongodb://myDbUser:passW0rT@0.0.0.0:27020/myDb
(password, database and addr have been changed).
I have verified that php mongo ext is installed, with this code:
echo extension_loaded("mongo") ? "loaded
" : "not loaded
"; //prints loaded.
if (class_exists('\MongoClient')) {
echo 'is Mongo Client'."
";//this is printed
}
else {
echo 'no Mongo Client'."
";
}
try {
$client = new MongoClient('mongodb://myDbUser:passW0rT@0.0.0.0:27020/myDb', []);
} catch (Exception $ex) {
echo $ex->getMessage();//prints Failed to connect to: 0.0.0.0:27020: Connection timed out
}
What is more strange I can connect to this database using MongoClient and in addition to this I can connect to this database by my local server running on my computer (Win 10).
The problem appears also when I use security.authorization set to enabled and without difference set to disabled – then I use dsn mongodb://0.0.0.0:27020 Unfortunately server's response always gives timeout error when I enter web addr using www (domain which is on the server where mongo database is installed).
It could be one clue that server where mongo is installed is server which runs as container which means that I have to add port number to connect eg. via ssh.
I even changed the server from ngix to apache and problem didn't disappear.