Compile extensions for ZendPHP
Zend by Perforce does not package a number of extensions often found in community PHP package repositories, or by extension all PECL extensions, for a variety of reasons:
-
Some are considered obsolete/superceded/insecure. For example:
-
mcrypt - this extension was dropped from PHP as being insecure, with a recommendation that users move to OpenSSL.
-
memcache - this extension was replaced by the memcached extension, and is no longer actively developed.
-
apcu_bc - users have been expected to migrate to the APCu API since 5.6.
-
-
Others we do not package due to licensing of the extension or one or more of its dependencies (commercial, GPL, or AGPL licenses, in particular). For example:
-
geoip
-
maxminddb
-
-
Some are under heavy development, and we are waiting for them to stabilize. For example:
-
Swoole and OpenSwoole
-
AST
-
-
Others do not have widespread use, or target technologies that are no longer actively developed. For example:
-
gearman
-
Compile an extension using zendphpctl (recommended)
For extensions we do not package, the easiest way to install is by using our zendphpctl utility. The command zendphpctl ext install {extension}
does the following:
-
Installs the PHP development packages for your OS.
-
Downloads either the most recent release of the extension, or if you include the version number (for example, "swoole-4.5.2"), the release associated with that version.
-
Configures, compiles, and installs the extension.
-
Provides a configuration stub for enabling the extension (and enable it for you immediately).
You may need to install additional dependencies. For more information, see Extensions dependencies.
Compile an extension manually
If you do not want to use zendphpctl, you can also manually install the developer packages that allow you to compile extensions.
-
On RPM-based systems, this is the "php {VERSION}zend-php-devel" package, where {VERSION} is the PHP minor version, without the "." separator (for example, 'php72zend-php-devel').
-
On DEB-based systems, this is the "php{VERSION}-zend-dev" package, where {VERSION} is the PHP minor version (for example, 'php7.2-zend-dev').
-
For RPM-based systems, they are found in {{/opt/zend/php{VERSION}zend/root/usr/bin/}}, where {version} is the PHP minor version number without the '.' separator; For example:
/opt/zend/php74zend/root/usr/bin/phpize
and/opt/zend/php74zend/root/usr/bin/php-config
. -
For DEB-based systems, they are found in /usr/bin, but have a suffix of {version}-zend, where {version} is the PHP minor version. For example,
/usr/bin/phpize7.4-zend
and/usr/bin/php-config7.4-zend
.
These packages will also install your build-essentials package, giving you all the tools needed for general extension compilation. You can download an extension package, and follow the extension compilation process documented in the PHP manual. To do this, you need to know where the phpize and php-config utilities exist.
The process then becomes:
tar xzf {extension-package} # for example: apcu_bc-1.0.5.tgz
cd {extension-version} # for example: apcu_bc-1.0.5
/path/to/phpize
./configure --with-php-config /path/to/php-config
make
make install
After installation, you also need to provide configuration to allow enabling it in your application. You can add it to your php.ini file, or via an include file (in RPM-based systems, these are in a php.d subdirectory co-located with the php.ini file; for DEB-based systems, these are in a conf.d subdirectory co-located with the php.ini file). The entry will look like:
extension={extension_name}.so
php --ini | grep Loaded
Extension dependencies
Be aware that some extensions require additional development and/or dynamic library packages on your system. Generally speaking, during the "configure" stage of compilation (which occurs with each of zendphpctl and manual compilation), you will get errors if any libraries are missing. You should typically be able to do an internet search for "{os} {os version} {name of missing package} package" using your preferred search engine to find the package you need. For example, "ubuntu 20.04 libgearman package".
During compilation, you will want the development variant of that package, as it has the files needed for compilation. For RPM-based systems, these have a "-devel" suffix; on DEB-based systems, they have a "-dev" suffix. For example, "libgearman-devel" or "libgearman-dev".
In production, after you compile your extension, you can use the package that omits the suffix; For example, "libgearman".