天天看點

phpize學習

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 directory

A successful install will have created extname.so and put it into the PHP extensions directory(生成一個.so檔案,自動放到php的擴充目錄下去,我覺得應該是phpize能夠自動偵測到php擴充目錄的位置).

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檔案建立在該目錄下。

步驟總結:

一、cd /usr/src/php源碼包目錄/ext/擴充目錄/ 

二、/usr/local/php5314/bin/phpize

三、./configure --with-php-config=/usr/local/php5314/bin/php-config

四、make && make install

ps:make install會自動将生成的.so擴充複制到php的擴充目錄下去,比如會提示已經安裝到 /usr/local/php/php-5.5.18/lib/php/extensions/no-debug-non-zts-20121212/目錄下去

五、剩下是配置php.ini

假如你的伺服器上安裝了多個版本php,那麼需要告訴phpize要建立基于哪個版本的擴充。通過使用--with-php-config=指定你使用哪個php版本。

比如:--with-php-config=/usr/local/php524/bin/php-config 

關于php-config檔案:是在php編譯生成後(安裝好),放在安裝目錄下的一個檔案。打開phpize檔案内容會發現,裡面定義好了php的安裝目錄等變量

prefix='/usr/local/php'

phpize是編譯安裝時候生成好的,記錄了當時安裝的一些資訊。并不能從其他地方拿個phpize來使用。

 phpize是在php安裝目錄下的一個檔案。比如我安裝了兩個php5.2 和php5.3那麼使用phpize也要使用對應版本的phpize才行。此時使用--with-php-config有什麼作用?

phpize工具一般在哪裡?

當php編譯完成後,php安裝目錄下的bin目錄下會有phpize這個腳本檔案。是以是去安裝好的php安裝目錄去找。