There are multiple types of extensions for PHP. PHP extensions are the ones located in the php-src repository directly and have the following installation procedure:
# Let's say php source code is located in /usr/src/php
cd /usr/src/php/ext/extension-name
phpize
./configure
make -jN
make -jN install-
Core Extensions
Core extensions are already included in PHP itself and cannot be left out of a PHP binary.
-
Bundled Extensions
Bundled extensions don't require additional libraries for compiling.
-
External Extensions
External extensions require additional libraries for compiling.
Pecl extensions are either some of the PHP core extensions that got moved to pecl
or the community contributed ones. They are located on pecl.php.net. Installation
is done with the simple pecl install command:
pecl install {extension-name}Since pecl command is part of a Pear system, sometimes you might want to omit
the Pear installation. You can install each pecl extension also by manually, by
downloading the .tgz TAR archive file compressed with gzip from the pecl.php.net
site and install it with the PHP development tools that come with the core PHP:
git clone https://github.com/{vendor}/{pecl-extension-src}.git
cd {pecl-extension-src}
phpize
./configure
make && make installBy default these images come with some pre-installed PHP extensions that are required to run some every day PHP applications. These include the following:
- bcmath
- bz2
- calendar
- ctype
- curl
- dom
- exif
- fileinfo
- filter
- ftp
- hash
- iconv
- json
- xml
- mbstring
- PCRE
- POSIX
- Mhash
- openssl
- readline
- SimpleXML
- Semaphore
- shmop
- sockets
- tokenizer
- XML Parser
- XMLReader
- XMLWriter
- Zip
- Zlib
PHP extensions:
- dba
- enchant
- gettext
- gd
- gmp
- imap
- intl
- ldap
- mcrypt
- mysqli
- mysqlnd
- pcntl
- pdo
- pdo_sqlite
- pdo_mysql
- pdo_pgsql
- PostgreSQL
- pspell
- recode
- snmp
- soap
- sqlite3
- tidy
- wddx
- xmlrpc
- xsl
PECL extensions:
These Docker images include a PHP.earth Alpine repository that comes with many pecl extensions and all PHP extensions.
apk add --no-cache php71-{extension-name}With Dockerfile, this can be used in the following way:
FROM phpearth/php
RUN apk add --no-cache php7.1-libsodiumHowever many times you'll want to install some other pecl extension as well. For
that you'll need to build it from source using the provided php71-dev package,
which includes phpize, php-config and PHP header files required to build
particular extension from source.
Here's a more generic way how to install such PHP extension. Replace names in curly brackets with extension you're installing:
FROM phpearth/php
RUN apk add --no-cache --virtual .build-deps php7.1-dev git gcc g++ linux-headers make \
&& mkdir -p /usr/src \
&& cd /usr/src \
# Download the extension source code from Git repository or pecl.php.net
&& git clone git://github.com/{vendor}/{php-extension} \
&& cd {php-extension} \
&& phpize \
&& ./configure \
# Build the extension with number of CPU cores
&& make -j "$(getconf _NPROCESSORS_ONLN)" \
&& make install \
# Enable the extension for PHP to load it as shared one
&& echo "extension={php-extension}.so" | tee /etc/php/conf.d/{php-extension}.ini \
# Clean build dependencies and source code
&& apk del --no-cache --purge .build-deps \
&& rm -rf /usr/src/*