Home  >  Article  >  Backend Development  >  php 装配mongo扩展

php 装配mongo扩展

WBOY
WBOYOriginal
2016-06-13 11:45:28717browse

php 安装mongo扩展
php mongo 扩展安装:



服务器环境Cent OS 5.6 64位, php版本 5.2.17编译安装,安装路径/usr/local/php



首先下载最新的php mongodb扩展源码,源码可以在http://pecl.php.net/package/mongo下载到

wget http://pecl.php.net/get/mongo-1.2.2.tgz

tar zxf mongo-1.2.2.tgz

cd mongo-1.2.2

进入文件夹后,首先运行phpize来准备编译扩展的环境,phpize这个程序的介绍在这里



/usr/local/php/bin/phpize






----------------------------------------------
以下为安装异常时的解决版本



基于本博客yum安装的lamp环境,phpize 位于 /usr/bin,php-config 位于/usr/bin,php.ini 位于/etc/

1.首先从http://pecl.php.net/package/mongo中选取适当版本的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

可以下载 http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz  http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz 安装包安装

或者 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

7.重启php-fpm或者web服务,查看phpinfo,如果有mongoDB,恭喜你,安装成功了



运行后执行结果如下:

Configuring for:

PHP Api Version:         20041225

Zend Module Api No:      20060613

Zend Extension Api No:   220060519



运行后,./configure 脚本就会生成了,这个时候我们运行./configure脚本来进行配置

./configure --with-php-config=/usr/local/php/bin/php-config

--with-php-config这个参数是告诉配置脚本php-config这个程序的路径,php-config的介绍在这里



上面命令在正确配置的环境下运行结果如下



creating libtool

appending configuration tag "CXX" to libtool

configure: creating ./config.status

config.status: creating config.h



这时用make来编译扩展
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-20060613/



完成后,请编辑你php.ini文件增加一行
extension=mongo.so
一般默认的编译php的ini文件在
/usr/local/php/etc/php.ini
重启你的web服务器或者php-fpm,打印phpinfo,如果看到mongo项表,那么mongodb的扩展安装成功了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn