Raspberry PI的安装配置过程
【略】
Nginx、PHP和MongoDB的安装过程
【略】
安装PHP的MongoDB驱动
指引来自这里(驱动安装)和这里(phpize找不到)。
运行以下指令以安装PHP开发环境和PEAR:
sudo apt-get install php5-dev sudo apt-get install php-pear
pear version pecl version
pecl search mongo sudo pecl install mongo
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
运行以下指令来打开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
测试
现在写个简单的页面来测试一下。输入指令:
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()); } ?>
问题
请自行放狗搜索。