nginx、php-fpm安装mongodb及驱动扩展
1.安装mongodb
linux下安装mongodb很简单,执行如下命令完成安装
wget http://downloads.mongodb.org/linux/mongodb-linux-i686-2.2.2.tgz
mv mongodb-linux-i686-2.2.2.tgz mongodb.2.2.2.tgz tar -zxvf mongodb.2.2.2.tgz mv mongodb-linux-i686-2.2.2/ /usr/local/mongodb/ cd /usr/local/mongodb/
2.4.9版本:
http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz
2.启动mongodb命令
cd /usr/local/mongodb/bin
/usr/local/mongodb/bin/mongod --port=12345 --dbpath=/usr/local/mongodb/mongodb_data --logpath=/home/wwwlog/mongodb.log --logappend&
这样mongodb就在端口12345运行了
3.安装mongodb的php驱动扩展
yum install php-pear cd /usr/local/php/bin sudo ./pecl install mongo
安装完成后会出现如下提示
Build process completed successfully Installing '/usr/lib/php/modules/mongo.so' install ok: channel://pecl.php.net/mongo-1.3.4 configuration option "php_ini" is not set to php.ini location You should add "extension=mongo.so" to php.ini
然后编辑php.ini添加
添加extension=mongo.so
4.测试脚本
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); header("Content-type: text/plain"); $connection = new Mongo(127.0.0.1:12345); $db = $connection->mydb; $collection = $db->mycollection; $myobj = array("first_name" => "John", "last_name" => "Doe", "age" => 30); $myobj2 = array("first_name" => "Jane", "last_name" => "Doe", "age" => 27); $collection->insert($myobj); $collection->insert($myobj2); $cursor = $collection->find(); foreach($cursor as $result) { echo "Name: " . $result["last_name"] . ", " . $result["first_name"] . "\n"; echo "Age: " . $result["age"] . "\n\n"; } $db->drop(); $connection->close(); ?>
ps:
如果安装过程中出现error while loading shared libraries: libmcrypt.so.4: cannot open shared object file: No such file or directory
安装对应的库即可,如果搞不定可以留言
可能出现的问题:
一:
-bash: /usr/local/bin/mongo: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
解决办法:
yum install ld-linux.so.2
二:
mongo: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
解决办法:
yum whatprovides libstdc++.so.6 yun install llibstdc++.so.6