Компиляция разделяемых расширений с помощью phpize
Иногда использование инсталятора pecl не подходит. Это может быть связано с тем, что вы находитесь за файерволом или из-за того, что расширение, которое вы хотите установить, недоступно в PECL-совместимом пакете (к примеру, расширения из SVN, у которых еще нет релизов). Если вам необходимо собрать такое расширение, вы можете использовать низкоуровневые утилиты для выполнения сборки вручную.
Команда phpize используется для подготовки окружения PHP-расширения. В следующем примере директория, где находятся исходные коды расширения, называется extname:
$ cd extname $ phpize $ ./configure $ make # make install
В случае успешной установки будет создан файл extname.so и помещен в PHP директорию расширений. Вам будет необходимо добавить строку extension=extname.so в php.ini перед использованием этого расширения.
Если в системе нет phpize, но существует возможность установки заранее скомпилированных пакетов (типа RPM), убедитесь, что установлена соответствующая версия пакета PHP для разработчиков, так как они часто содержат команду phpize с подходящими файлами заголовков для сборки PHP и его расширений.
Для дополнительной информации используйте команду phpize --help.
Коментарии
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.
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".
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
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
If you failed to run phpize command, then you should install php-devel package. Command line to install the php-devel package using yum is: yum install php-devel.
If you failed to compile the PECL extension, then you should install gcc package. Command line to install the gcc package using yum is: yum install gcc.