Monday, January 7. 2008
Over the past few months there has been an increasing amount of conversation about
Zend Core, especially around how best to compile custom extensions for it. While Core does ship with a large list of extensions (which are all QA'd and supported by Zend) there are times when you would like to include non-official extensions from
PECL for various reasons. Since there isn't a great deal of documentation out there about how to do this I thought I'd write a quick tutorial.
Basically, to compile an extension for Zend Core you need to go through the following steps:
1) Download the source of your desired extension
2) Create the ./configure script for the extension as a stand-alone shared lib ("PHPize" it)
3) Compile and install the extension
4) Add the extension to your php.ini file
Where most people get caught up is in step two of this process. So, how does one create the correct ./configure script? In a vanilla PHP from php.net, you would do this by executing the
phpize command in the extension's source directory:
$ cd /path/to/my/pecl/ext
$/usr/local/bin/phpize
When executed, this shell script will execute the necessary commands to prepare the extension for compilation and create a
configure script in the extension's directory which you can then use to compile your extension. Think of this
configure script as a mini-version of the standard PHP distribution version which only will work for the specific extension you are building:
$ ./configure --enable-my-ext
$ make
$ sudo make install
When building an extension for Zend Core, the process is almost identical. In fact, the only real difference is that you need to use the Zend Core version of
phpize (and perhaps provide some paths to certain files)..for example:
$ cd /path/to/my/pecl/ext
$ /usr/local/Zend/Core/bin/phpize
Because Zend Core is installed it a directory under /usr/local/Zend, chances are when you attempt to execute the ./configure script it will complain that it can't find a program called 'php-config'. To get around this, you'll need to make sure you also include --with-php-config as part of any ./configure command you need to compile the extension:
$ ./configure --enable-my-ext --with-php-config=/usr/local/Zend/Core/bin/php-config
$ make
$ make install
For most cases that should be all you need to compile the extension for Zend Core!
If you need to compile a PDO Driver
One of the few exceptions to the directions above is when you attempt to compile a custom PDO extension. For example, many people are interested in compiling the
pdo_sqlite drivers for PDO into Core. Unfortunately, currently such a process is not officially supported by Zend. However, if you feel that you are comfortable enough you can "tweak" Zend Core to allow you to do so by following these steps:
1) Determine the PHP version your version of Zend Core uses by viewing the phpinfo() page of Zend Core.
2) Download the same PHP version from php.net (or check it out from the repository)
$ cvs -d:pserver:cvsread@cvs.php.net:/repository co -r php_5_2_5 php-src
3) Copy all of the PDO header files into Zend Core
$ cd /path/to/php-src/ext/pdo
$ mkdir /usr/local/Zend/Core/includes/ext/pdo
$ cp *.h /usr/local/Zend/Core/includes/ext/pdo
4) Use the procedure outlined above for compiling a custom extension for Core to compile a custom version of the PDO base extension (in the ext/pdo directory of your PHP source install)
$ cd /path/to/php-src/ext/pdo
$ /usr/local/Zend/Core/bin/phpize
$ ./configure --enable-my-ext --with-php-config=/usr/local/Zend/Core/bin/php-config
$ make
$ make install
5) Compile your custom PDO drivers
$ cd /path/to/php-src/ext/pdo_sqlite
$ /usr/local/Zend/Core/bin/phpize
$ ./configure --with-pdo-sqlite --with-php-config=/usr/local/Zend/Core/bin/php-config
$ make
$ make install
Note, when doing this process chances are you will have to compile custom version of
all PDO-related extensions for compatibility reasons. Once you have everything compiled you can enable the extensions in PHP by modifying the php.ini file (don't forget to restart the server afterwards!). Assuming everything worked as planned, you should be able to see the extension's information within phpinfo() and the Zend Core GUI will show the extension in the extension list (although you will not be able to control it, etc as you would a standard supported extension).
Hope this helps!