php 裝配mongo擴充
來源:互聯網
上載者:User
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的擴充安裝成功了