以下是我走位 php 新手第一次安装 mongo 模块的步骤:
1. 首先从在网上选取适当版本的 mongoDB 扩展包下载;
2. 解压扩展包, 并且进入解压目录;
- tar -zxf mongo-1.4.1.tgz
- cd mongo-1.4.1
3. 在 mongo-1.3.2 目录下执行 phpize, 命令如下:(注: 此工具是 php 添加扩展的工具, 我的 phpize 位置为 / www/php/bin/phpize)
/usr/local/php/bin/phpize
注: 肯能会出如下错误:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script
问题在于: 未安装 m4 与 autoconf
继续执行: yum -y install m4 autoconf 会生成 configure 文件
4. 执行如下命令:
./configure --with-php-config=/usr/local/php/bin/php-config
注:-with-php-config 参数需要指定的是 php-config 文件的位置, 而不是 php.ini 文件的位置
- creating libtool
- appending configuration tag "CXX" to libtool
- configure: creating ./config.status
- config.status: creating config.h
5. 查看配置信息如果无误的话, 编译并安装:
make&&make install
正确编译执行结果如下:
Build complete.
Don't forget to run'make test'.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20130712/
6. 编译安装完成后, 在 php.ini 中添加一句:
extension=mongo.so
来源: http://www.bubuko.com/infodetail-2614966.html