转:http://www.server110.com/mongodb/201403/7596.html
https://github.com/RickP/mongopi
MongoDB 2.1.1 for the Raspberry Pi - Work in progress!
Install the needed packages on Raspian:
sudo apt-get install git-core build-essential scons libpcre++-dev xulrunner-dev libboost-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev
Checkout this repo:
git clone git://github.com/RickP/mongopi.git
Build it (this will take very long!):
cd mongopi scons
Install it:
sudo scons --prefix=/opt/mongo install
This will install mongo in /opt/mongo, to get other programs to see it, you can add this dir to your $PATH:
PATH=$PATH:/opt/mongo/bin/ export PATH
Nginx、PHP和MongoDB的安装过程
【略】
安装PHP的MongoDB驱动
指引来自这里(驱动安装)和这里(phpize找不到)。
运行以下指令以安装PHP开发环境和PEAR:
sudo apt-get install php5-dev
sudo apt-get install php-pear
然后,运行以下指令以检测PEAR的安装(可以略过):
pear version
pecl version
检查、安装和编译MongoDB驱动:
pecl search mongo
sudo pecl install mongo
成功后会提示mongo.so的路径和修改php.ini的方法:
Build process completed successfully
Installing '/usr/lib/php5/20100525+lfs/mongo.so'
install ok: channel://pecl.php.net/mongo-1.4.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
在raspberry Pi下,我们还是用nano来编辑文件,在php.ini文件中并没有mongodb的踪迹,所以我们得自己添加:
运行以下指令来打开php.ini:
sudo nano /etc/php5/fpm/php.ini
在末尾加上以下内容,然后按CTRL+X,再按Y保存退出:
...
[MongoDB]
; igame:Dec-24-2013: Add MongoDB extension.
extension=mongo.so
运行以下指令重新启动php-fpm:
sudo killall php5-fpm
sudo /etc/init.d/php5-fpm restart
然后,用浏览器打开info.php页面以检查成果。注意,Nginx的根目录是/usr/share/nginx/www。如果看到mongo部分,就成功了。
测试
现在写个简单的页面来测试一下。输入指令:
sudo nano /usr/share/nginx/www/testmongo.php
再输入以下内容:
<?php
echo '<center><h1>PHP+MongoDB Test</h1><br /></center>';
try
{
$mongo = new Mongo(/*"localahost:27101"*/);
$blog = $mongo->blog;
$posts = $blog->posts;
$it = $posts->find();
if ($it->count() < 1)
{
$posts->insert(array('title' => 'Hello, MongoDB!'));
$posts->insert(array('title' => 'Hello, igame!'));
$posts->insert(array('title' => 'Hello, php!'));
$posts->insert(array('title' => 'Hello, Nginx!'));
}
else
{
echo $it->count() . ' document(s) found. <br />';
foreach($it as $obj)
{
echo "title: [" . $obj["title"] . "]<br />";
}
}
$mongo->close();
}
catch(MongoConnectionException $e)
{
die('Error in connection to MongoDB');
}
catch(MongoException $e)
{
die('Error:' . $e->getMessage());
}
?>
保存退出。用浏览器打开看看结果。
问题
请自行放狗搜索。