无废话 MongoDB 及 PHP 扩展编译安装

操作系统环境:Gentoo Linux

需要使用 scons 编译安装:

emerge scons

安装 mongodb 依赖库:

emerge boost
emerge libpcre
export CFLAGS=”-DJS_C_STRINGS_ARE_UTF8″ # 编译spidermonkey支持utf8
emerge spidermonkey

安装 mongodb:

# 1.6.5 版本

cd /work/setup
wget http://downloads.mongodb.org/src/mongodb-src-r1.6.5.tar.gz
tar zxf mongodb-src-r1.6.5.tar.gz
cd mongodb-src-r1.6.5
scons all
scons –full install

# 2.0.0 版本(2011-09-13 更新)

cd /work/setup
wget http://downloads.mongodb.org/src/mongodb-src-r2.0.0.tar.gz
tar zxf mongodb-src-r2.0.0.tar.gz
cd mongodb-src-r2.0.0
scons all
scons –full install

启动 mongodb 服务器:
创建默认的数据库目录,创建后启动 mongod:

mkdir -p /data/db
/usr/local/bin/mongod

在系统自动启动队列文件 /etc/conf.d/local.start 中添加:

/usr/local/bin/mongod –fork –logpath /var/log/mongodb.log –logappend

安装 PHP 扩展:

wget http://pecl.php.net/get/mongo-1.1.4.tgz
tar zxf mongo-1.1.4.tgz
cd mongo-1.1.4
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install

# 2011-09-13 更新

wget http://pecl.php.net/get/mongo-1.2.4.tgz
tar zxf mongo-1.2.4.tgz
cd mongo-1.2.4
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install

最后在 php.ini 尾部加上:

extension = mongo.so

— EOF —