k668 发表于 2018-10-27 06:25:52

Linux下为PHP添加MongoDB扩展

  基于本博客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.gzhttp://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,恭喜你,安装成功了。

页: [1]
查看完整版本: Linux下为PHP添加MongoDB扩展