UNIX: Compiling PHP Extensions

This procedure describes how to compile a PHP extension. Zend Server includes over 77 extensions however there still may be a PHP extension that you want to compile by yourself.


  • PHP Tools:
    • PECL (PHP Extension Community Library): PECL is a repository for PHP extensions, providing a directory of all known extensions and hosting facilities for download and development of PHP extensions. - It is also a tool supplied in the form of a small shell script with PHP code behind it to retrieve extensions from the aforementioned repository.
    • phpize: a shell script to generate a configure script for PHP extensions
  • Build Tools:
    While PHP can be built using many different tool chains, this article will focus on using the GNU tool chain. The main tools where PHP is concerned are:
    • autoconf: automatic configure script builder. This is called by the phpize script.
    • automake: a tool for generating GNU Standards-compliant Makefiles
    • libtool: Generic library support script. Libtool hides the complexity of generating special library types (such as shared libraries) behind a consistent (sort of :) ) interface.
    • GNU make: a GNU tool for controlling the generation of executables and other non-source files of a program from the program's source files
    • GCC: PHP extensions are typically written in C. Hence, in order for them to compile, you would need a C compiler. While GCC now stands for GNU compiler Collection and is no longer just a GNU C Compiler, for our purposes we only need the C part of the collection. GNU's elf-binutils package: The programs in this package are used to assemble, link and manipulate binary and object files.

Install the following packages:

Users of distributions with package managers (mainly Debian, Ubuntu, RHEL, CentOS ) should install the following packages from their distribution's repository: gcc, make, autoconf, automake and libtool. Some of these tools depend on each other, for instance the libtool package depends on the gcc package, but no damage can be done from specifying all of them.


Users who utilize distributions that do not have package managers (Linux from scratch anyone?), can compile these tools themselves or obtain pre-compiled binaries for them quite easily.

Additionally, you can compile a PHP extension from the main PHP source (as opposed to PECL). This requires installing a package from the Zend Server repository called php-5.3-source-Zend Server or php-5.4-source-Zend Server depending on your Zend Server's major PHP version. This package includes full PHP sources as patched, for security or optimization concerns, by the Zend development team. This ensures that you are using the exact same source code we used when building Zend Server.