PECL 扩展库安装
在线手册:中文  英文

用 phpize 编译共享 PECL 扩展库

有时候不能用 pecl 安装命令。这可能是因为在防火墙后面,或者是因为想要安装的扩展库还没有 PECL 兼容的包,例如 SVN 中尚未发布的扩展库。如果要编译这种扩展库,可以用更底层的编译工具来手工进行编译。

phpize 命令是用来准备 PHP 扩展库的编译环境的。下面例子中,扩展库的源程序位于 extname 目录中:

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

成功的安装将创建 extname.so 并放置于 PHP 的扩展库目录中。需要调整 php.ini,加入 extension=extname.so 这一行之后才能使用此扩展库。

如果系统中没有 phpize 命令并且使用了预编译的包(例如 RPM),那要安装 PHP 包相应的开发版本,此版本通常包含了 phpize 命令以及相应的用于编译 PHP 及其扩展库的头文件。

使用 phpize --help 命令可以显示此命令用法。


PECL 扩展库安装
在线手册:中文  英文

用户评论:

admin at eexit dot net (2012-06-19 19:33:06)

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.so
modules/xdebug.so: ELF 64-bit LSB dynamic lib AMD64 Version 1, dynamically linked, not stripped, no debugging information available

jplahti (2008-08-28 23:48:18)

Minimizing harm on upgrading extensions on busy server.
I upgraded (phpize,make... way) APC-extension on quite busy server and found out that Apache segfaults if i just restart it gracefully with the new extension in place. I found a way around this, so that the users of the server only see small slow down of the services.
1. Comment out extension loading (old extension) in php.ini (or separate .ini-file).
2. Restart Apache gracefully (now system runs without extension).
3. Replace old extension with new version (can be done already before first restart) and edit .ini again to include extension.
4. Restart Apache gracefully again (new extension loads).
Of course this only works for extensions which your php-application can live without for a short period of time. ;-)

Brian (2008-05-01 11:39:49)

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

Glen (2007-05-17 16:07:47)

When you have multiple installations of PHP, running phpize from a specific installation will not force the module to be compiled with that installation's include files.
In my case, I had a standard PHP distribution installed, and am evaluating Zend Core / Zend Platform, which installed it's own Apache & PHP in a /usr/local/Zend/.. install path. It was missing the json.so module, so I had to compile my own.
Running Zend Core's phpize, the output indicates that configuration for that module will occur. But when running ./configure, the standard installation's include files are used. The result json.so being compiled against the wrong PHP would not load when Zend Core's php initializes.
The only way I could see to correct the situation was to temporarily change the standard PHP include path to point to the Zend Core's include files. In my case, I made a backup copy of /usr/include/php5 and did a "ln -s /usr/local/Zend/Core/include/php/ /usr/include/php5".

dmytton at php dot net (2005-12-03 11:45:34)

In some situations (e.g. on a cPanel server), the built extension will not be placed into the correct extensions directory by the make install process. Use your phpinfo() output to determine what the correct extension_dir path is and move the generated .so file into that directory. The extension=extname.so line in php.ini will then find the extension file correctly.

易百教程