2011-06-13 26 views
0

我很喜欢玩NoSQL,特别是MongoDB。为此,我在外部Linux系统中安装的MongoDB通过ssh方式连接到服务器并运行以下命令:我已经在服务器上安装了MongoDB。现在怎么办?

sudo pecl install mongo 

蒙戈似乎已经正确安装,现在有一个“蒙戈”部分,如果我跑phpinfo()

但现在呢?我从这里到使用它在生产中似乎遇到麻烦。问题是,我不认为MongoDB服务正在运行,并且我没有配置任何MongoDB用户,因为我不知道如何去做。其结果是,下面的测试脚本失败:

<?php 

// connect 
$m = new Mongo(); 

// select a database 
$db = $m->comedy; 

// select a collection (analogous to a relational database's table) 
$collection = $db->cartoons; 

// add a record 
$obj = array("title" => "Calvin and Hobbes", "author" => "Bill Watterson"); 
$collection->insert($obj); 

// add another record, with a different "shape" 
$obj = array("title" => "XKCD", "online" => true); 
$collection->insert($obj); 

// find everything in the collection 
$cursor = $collection->find(); 

// iterate through the results 
foreach ($cursor as $obj) { 
    echo $obj["title"] . "\n"; 
} 

?> 

当我收到以下错误信息:

Fatal error: Uncaught exception 'MongoConnectionException' with message 'connecting to failed: Transport endpoint is not connected' in /home/[username]/public_html/mongodbtest/index.php:4 Stack trace: #0 /home/[username]/public_html/mongodbtest/index.php(4): Mongo->__construct() #1 {main} thrown in /home/woohoobi/public_html/mongodbtest/index.php on line 4

如何从这里到MongoDB的使用?

回答

1

您从未真正安装过MongoDB,而是可以连接到MongoDB实例的PHP扩展。安装MongoDB downloading it并将其安装到您的服务器上,然后从您的PHP脚本连接到它。

+0

谢谢。我跑了'curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz> mongo.tgz' - was [this](http://i.imgur.com/QmJuW。 PNG)应该发生? o_O – 2011-06-13 13:21:22

+0

这很好,现在只需解压该文件(我相信'tar zxf')并从那里安装。或者,你可以从'apt'或'yum'安装它。 – 2011-06-13 13:25:52

+0

我全力以赴!再次感谢。我按照此页面上的说明操作:http://www.mongodb.org/display/DOCS/Quickstart+Unix – 2011-06-13 13:33:45

相关问题