【发布时间】:2013-08-26 08:24:14
【问题描述】:
我正在尝试在本地电脑上运行我的应用程序。在云上一切看起来都很好,它可以工作并使用以下代码连接到 MongoDB:
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = $mongo_config["hostname"];
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = $mongo_config["port"];
// The database you want to work from (required)
$config['mongo_db'] = $mongo_config["db"];
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = $mongo_config["username"];
$config['mongo_pass'] = $mongo_config["password"];
但由于我无法从本地电脑获取 vcap_services,我使用常量值进行连接,以将我的应用程序连接到 appfog 上的远程 mongo 服务器:
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = "***";
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = "***";
// The database you want to work from (required)
$config['mongo_db'] = "db";
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = "***";
$config['mongo_pass'] = "***";
但是当我尝试通过http://localhost/my-app 执行应用程序时,它给了我这个错误:
Unable to connect to MongoDB: Failed to connect to: ***: Connection timed out
可能是什么问题?
* 值被删除以保护隐私。
【问题讨论】:
-
你能连接到
http://localhost:28017/吗? -
是的,但主要问题不在于 localhost。我有另一个像 10.*.*.* 这样的主机,我需要从本地连接到 appfog。
标签: php codeigniter mongodb remote-access appfog