安装MongoDB
1、下面安装MongoDB,先下载:
- cd /usr/local/src
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz
2、解压,进入目录:
- tar -zxvf mongodb-linux-x86_64-2.6.4.tgz -C /usr/local/src
- cd mongodb-linux-x86_64-2.6.4
3、创建数据库和日志的目录:
- mkdir log
- mkdir db
4、以后台运行方式启动:
- ./bin/mongod --dbpath=./db --logpath=./log/mongodb.log --fork --auth
会显示如下内容:
- about to fork child process, waiting until server is ready for connections.
- forked process: 4623
- child process started successfully, parent exiting
输入netstat -nalupt | grep mongo
- tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 4623/./bin/mongod
安装mongodb扩展
下载php-mongodb扩展
wget http://pecl.php.net/get/mongo-1.6.12.tgz
解压
tar xvzf mongo-1.6.12
编译安装
cd mongo-1.6.12
phpize
./configure --with-php-config=/usr/bin/php-config
make && make install
在安装过程中可能会报以下错误
/var/tmp/mongo/contrib/php-ssl.h:33:25: error: openssl/evp.h: No such file or directory
需要安装openssl-devel
yum install openssl-devel
在php.ini文件中添加extension=mongo.so
extension=mongo.so
重启Apache 或者Nginx