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

用 phpize 编译共享 PECL 扩展库

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

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

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

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

PECL 扩展库安装
在线手册:中文 英文
PHP手册 - N: 用 phpize 编译共享 PECL 扩展库


jplahti (29-Aug-2008 07:48)

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 (01-May-2008 07:39)

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 (18-May-2007 12:07)

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 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 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 (03-Dec-2005 07:45)

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 line in php.ini will then find the extension file correctly.