phpize で共有 PECL 拡張モジュールをコンパイルする方法

時には pecl インストーラを使用するという選択肢が使えない場合もあります。 たとえばファイアウォールの内部で作業をしている場合がそうですし、 まだリリースされていない git 版のように PECL パッケージ形式になっていないものをインストールする場合も それにあてはまります。このようなモジュールをビルドする必要がある場合は、 より低レベルなビルドツールを使用して手動でビルドします。

PHP 拡張モジュールのビルド環境を準備するために、 phpize コマンドを使用します。以下の例では、 拡張モジュールのソースが extname というディレクトリにあると仮定します。

$ cd extname
$ phpize
$ ./configure
$ make
# make install

上手くいけば、extname.so が作成され、 それが PHP の 拡張モジュールディレクトリ に置かれます。 この拡張モジュールを使用する前に、php.iniextension=extname.so という行を追加する必要があります。

コンパイル済みのパッケージ (RPM など) を使用している場合などで、もし phpize コマンドが見つからない場合は、適切な 開発版の PHP パッケージをインストールしましょう。 PHP や拡張モジュールをビルドするために必要なヘッダファイルや phpize コマンドは、このパッケージに含まれます。

使用法についての詳細な情報を表示するには、 phpize --help を実行します。

add a note

User Contributed Notes 2 notes

up
70
Brian
17 years ago
If you have multiple PHP versions installed, you may be able to specify for which installation you'd like to build by using the --with-php-config option during configuration.--with-php-config=[Insert path to proper php-config here]For example (my case):./configure --with-php-config=/usr/local/php5/bin/php-config5
up
7
admin at eexit dot net
13 years ago
When compiling an extension for a stack which is 64 bits (for example) and your compiler is configured to compile in 32 bits, you can manually compile your extensions using C flags before your configure.Example: my system compiler is 32 bits and my stack is 64 bits. To compile my xdebug:# phpize# CFLAGS=-m64 CPPFLAGS=-m64 CCASFLAGS=-m64 ./configure --enable-xdebug# gmake# file modules/xdebug.somodules/xdebug.so:      ELF 64-bit LSB dynamic lib AMD64 Version 1, dynamically linked, not stripped, no debugging information available
To Top