软瓷生产商:MongoDB安装(带PHP扩展)

来源:百度文库 编辑:九乡新闻网 时间:2024/05/07 05:57:37

一、MongoDB安装

1. apt-get安装:

Mongodb
CouchDB一样,是一种文档结构的数据库,使用C++的开发。MongodbUbuntu安装包还是由mongodb.org所托管的,需要在/etc/apt/sources.list里面添加新的源:
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages)在这找
deb http://downloads.
mongodb.org/distros/ubuntu 9.10 10gen

deb http://downloads.mongodb.org/distros/debian 5.0 10gen

然后使用apt的命令进行安装:

W: GPG error: http://downloads.mongodb.org 9.10 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 9ECBEC467F0CEB10

W: GPG error: http://downloads.mongodb.org 5.0 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 9ECBEC467F0CEB10

W: You may want to run apt-get update to correct these problems


gpg --keyserver pgpkeys.mit.edu --recv-key 9ECBEC467F0CEB10

gpg -a --export 9ECBEC467F0CEB10 | apt-key add -
apt-get update
apt-get install
mongodb-stable
需要额外安装的包有很多:

libnspr4-dev libnss3-dev libpcrecpp0
mongodb xulrunner-1.9.1-dev xulrunner-dev
安装完成后,你可以访问本地的28017(http://127.0.0.1:28017)端口,查看服务是否正常启动。
2.
源码安装
初学者建议使用下述方式:
===============================================================================
1.
获取mongodb

sudo wget http://downloads.
mongodb.org/linux/mongodb-linux-i686-latest.tgz

2.
解压

tar xzf
mongodb-linux-i386-latest.tgz

3.
创建数据库目录

mkdir -p /home/shenzhe/
mongodb

4.
运行

bin/mongod run –dbpath=/home/shenzhe/
mongodb &

5.  
使用自带客户端连接
bin/mongo

6.  
测试
db.foo.save( { a : 1 } )
db.foo.findOne()

二、安装PHP扩展

apt-get install php-pear php5-dev

pecl install mongo

配置PHP

vi /etc/php5/conf.d/mongodb.ini

extension=mongo.so

[mongo]

; If the driver should reconnect to mongo

mongo.auto_reconnect = true

; Whether to allow persistent connections

mongo.allow_persistent = On

; Maximum number of persistent connections (-1 means unlimited)

mongo.max_persistent = -1

; Maximum number of links (persistent and non-persistent, -1 means unlimited)

mongo.max_connections = -1

; Default host for mongo connection

mongo.default_host = www.example.com

; Default port for mongo database

mongo.default_port = 42

; When saving files to the database, size of chunks to split them into

mongo.chunk_size = 1024

; Specify an alternate character to $ to use for special db functions ($set, $push, $exists, etc.)

mongo.cmd = "$"