Compiling shared PECL extensions with phpize
Sometimes, using the pecl installer is not an option. This could be because you're behind a firewall, or it could be because the extension you want to install is not available as a PECL compatible package, such as unreleased extensions from SVN. If you need to build such an extension, you can use the lower-level build tools to perform the build manually.
The phpize command is used to prepare the build environment for a PHP extension. In the following sample, the sources for an extension are in a directory named extname:
$ cd extname 進入到源碼包中的擴展目錄,這個擴展目錄,通俗理解,若是要安裝操做gd庫,那麼下載到這個庫的源碼後,解壓源碼會有個一個目錄,進入這個目錄。
$ phpize 運行phpize。路徑不必定在這個目錄下,但通常是在安裝目錄下(按照我理解,每一個phpize與具體的版本有關,不可能通用),去尋找phpize運行。以後會生成了一個configure文件
$ ./configure 運行。 若是生成基於數據庫的擴展,須要加上參數運行:1,--with-php-config。2,"--with-具體的數據庫參數".好比, --with-pgsql、--with-mysql
$ make
# make install 將會生成一個extname.so的擴展,被放到了PHP extensions directoryphp
A successful install will have created extname.so and put it into the PHP extensions directory(生成一個.so文件,自動放到php的擴展目錄下去,我以爲應該是phpize可以自動偵測到php擴展目錄的位置).mysql
You'll need to and adjust php.ini and add an extension=extname.so line before you can use the extension.
If the system is missing the phpize command, and precompiled packages (like RPM's) are used, be sure to also install the appropriate devel version of the PHP package as they often include the phpize command along with the appropriate header files to build PHP and its extensions.
Execute phpize --help to display additional usage information.
phpize的做用能夠這樣理解:偵測環境(phpize工具是在php安裝目錄下,基於這點phpize對應了當時的php環境,因此是要根據該php的配置狀況生成對應的configure文件),創建一個configure文件。必須在一個目錄下去運行phpize。那麼phpize就知道你的的環境是哪一個目錄,而且configure文件創建在該目錄下。sql
步驟總結:數據庫
1、cd /usr/src/php源碼包目錄/ext/擴展目錄/
2、/usr/local/php5314/bin/phpize
3、./configure --with-php-config=/usr/local/php5314/bin/php-config
4、make && make install服務器
ps:make install會自動將生成的.so擴展複製到php的擴展目錄下去,好比會提示已經安裝到 /usr/local/php/php-5.5.18/lib/php/extensions/no-debug-non-zts-20121212/目錄下去
5、剩下是配置php.iniapp
假如你的服務器上安裝了多個版本php,那麼須要告訴phpize要創建基於哪一個版本的擴展。經過使用--with-php-config=指定你使用哪一個php版本。
好比:--with-php-config=/usr/local/php524/bin/php-config
關於php-config文件:是在php編譯生成後(安裝好),放在安裝目錄下的一個文件。打開phpize文件內容會發現,裏面定義好了php的安裝目錄等變量工具
prefix='/usr/local/php'ui
phpize是編譯安裝時候生成好的,記錄了當時安裝的一些信息。並不能從其餘地方拿個phpize來使用。spa
phpize是在php安裝目錄下的一個文件。好比我安裝了兩個php5.2 和php5.3那麼使用phpize也要使用對應版本的phpize才行。此時使用--with-php-config有什麼做用?debug
phpize工具通常在哪裏?
當php編譯完成後,php安裝目錄下的bin目錄下會有phpize這個腳本文件。因此是去安裝好的php安裝目錄去找。