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
$ phpize
$ ./configure
$ make
# make install

A successful install will have created extname.so and put it
into the PHP
extensions directory. 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.

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 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.

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".