2020-02-21 12:22:59 +00:00
[![Test recent ](https://github.com/mlocati/docker-php-extension-installer/workflows/Test%20recent/badge.svg )](https://github.com/mlocati/docker-php-extension-installer/actions?query=workflow%3A%22Test+recent%22)
2018-04-12 07:25:43 +00:00
2018-04-11 15:39:10 +00:00
# Easy installation of PHP extensions in official PHP Docker images
This repository contains a script that can be used to easily install a PHP extension inside the [official PHP Docker images ](https://hub.docker.com/_/php/ ).
2020-01-08 09:09:44 +00:00
The script will install all the required APT/APK packages; at the end of the script execution, the no-more needed packages will be removed so that the image will be much smaller.
2020-03-03 11:07:51 +00:00
Supported docker images are all the Alpine/Debian versions, except for PHP 5.5 where we only support Debian 8 (jessie) (that is, `php:5.5` , `php:5.5-apache` , `php:5.5-cli` , `php:5.5-fpm` , `php:5.5-zts` ).
See also the notes in the [Special requirements ](#special-requirements ) section.
2018-04-11 15:39:10 +00:00
## Usage
2020-01-08 09:09:44 +00:00
You have two ways to use this script within your `Dockerfile` s: you can download the script on the fly, or you can grab it from the [`mlocati/php-extension-installer` Docker Hub image ](https://hub.docker.com/r/mlocati/php-extension-installer ).
With the first method you are sure you'll always get the very latest version of the script, with the second method the process is faster since you'll use a local image.
2018-04-11 15:39:10 +00:00
2020-01-08 09:09:44 +00:00
For example, here are two `Dockerfile` s that install the GD and xdebug PHP extensions:
### Downloading the script on the fly
```Dockerfile
2018-04-11 15:39:10 +00:00
FROM php:7.2-cli
2020-12-10 14:59:21 +00:00
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
2018-04-11 15:39:10 +00:00
2020-11-05 10:43:10 +00:00
RUN chmod +x /usr/local/bin/install-php-extensions & & sync & & \
2018-04-11 15:45:25 +00:00
install-php-extensions gd xdebug
2018-04-11 15:39:10 +00:00
```
2020-01-08 09:09:44 +00:00
### Copying the script from a Docker image
2019-10-09 15:11:51 +00:00
2020-01-08 09:09:44 +00:00
```Dockerfile
2019-10-09 15:11:51 +00:00
FROM php:7.2-cli
2020-12-10 14:59:21 +00:00
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
2019-10-09 15:11:51 +00:00
RUN install-php-extensions gd xdebug
```
Let users install a specific PHP module version
Test: amqp,apcu,gmagick,http,pecl_http,igbinary,memcache,mailparse,memcached,mongodb,mosquitto,msgpack,oauth,opencensus,parallel,pcov,pdo_sqlsrv,sqlsrv,propro,protobuf,pthreads,raphf,rdkafka,redis,solr,ssh2,uuid,xdebug,uopz,xhprof,yaml
2020-12-02 17:19:24 +00:00
### Installing a specific version of an extension
Simply append `-<version>` to the module name.
For example:
```sh
install-php-extensions xdebug-2.9.7
```
2020-12-16 10:34:30 +00:00
### Installing composer
You can also install [composer ](https://getcomposer.org/ ), and you also can specify a major version of it, or a full version.
Examples:
```sh
# Install the latest version
install-php-extensions @composer
# Install the latest 1.x version
install-php-extensions @composer -1
# Install a specific version
install-php-extensions @composer -2.0.2
```
2018-04-11 15:39:10 +00:00
## Supported PHP extensions
<!-- START OF EXTENSIONS TABLE -->
<!-- ########################################################### -->
<!-- # # -->
<!-- # DO NOT EDIT THIS TABLE: IT IS GENERATED AUTOMATICALLY # -->
<!-- # # -->
<!-- # EDIT THE data/supported - extensions FILE INSTEAD # -->
<!-- # # -->
<!-- ########################################################### -->
2020-09-19 02:59:16 +00:00
| Extension | PHP 5.5 | PHP 5.6 | PHP 7.0 | PHP 7.1 | PHP 7.2 | PHP 7.3 | PHP 7.4 | PHP 8.0 |
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
2020-12-22 18:29:48 +00:00
| amqp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| apcu | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-10-18 16:16:54 +00:00
| apcu_bc | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
2020-09-19 02:59:16 +00:00
| bcmath | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| bz2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| calendar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| cmark | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| dba | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| decimal | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| enchant[*](#special-requirements-for-enchant) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-10 11:16:02 +00:00
| ev | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2020-09-19 02:59:16 +00:00
| exif | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ffi | | | | | | | ✓ | ✓ |
| gd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gettext | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gmagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| gmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-14 16:58:42 +00:00
| gnupg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2020-12-03 16:43:11 +00:00
| grpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| http | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| igbinary | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-17 16:10:23 +00:00
| imagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| imap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| interbase | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | |
| intl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-10 14:44:10 +00:00
| ioncube_loader | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2020-09-19 02:59:16 +00:00
| ldap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mailparse | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-10 17:09:48 +00:00
| maxminddb | | | | | ✓ | ✓ | ✓ | ✓ |
2020-12-09 08:39:56 +00:00
| mcrypt | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| memcache | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| memcached | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mongo | ✓ | ✓ | | | | | | |
2020-12-07 12:59:13 +00:00
| mongodb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-11-28 13:53:31 +00:00
| mosquitto | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2020-12-09 08:39:56 +00:00
| msgpack | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| mssql | ✓ | ✓ | | | | | | |
| mysql | ✓ | ✓ | | | | | | |
| mysqli | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-09 08:39:56 +00:00
| oauth | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-11 14:24:59 +00:00
| oci8 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-09 10:07:11 +00:00
| odbc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| opcache | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| opencensus | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| parallel[*](#special-requirements-for-parallel) | | | | ✓ | ✓ | ✓ | ✓ | |
| pcntl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pcov | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-09 08:48:55 +00:00
| pdo_dblib | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| pdo_firebird | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_mysql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-28 12:28:20 +00:00
| pdo_oci | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| pdo_odbc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_pgsql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_sqlsrv | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| pgsql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| propro | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| protobuf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pspell | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pthreads[*](#special-requirements-for-pthreads) | ✓ | ✓ | ✓ | | | | | |
| raphf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| rdkafka | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| recode | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | |
2020-09-21 13:13:57 +00:00
| redis | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| shmop | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2021-01-03 14:18:14 +00:00
| smbclient | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| snmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2021-01-02 19:37:57 +00:00
| snuffleupagus | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| soap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sockets | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| solr | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sqlsrv | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| ssh2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2020-12-16 16:33:31 +00:00
| swoole | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| sybase_ct | ✓ | ✓ | | | | | | |
| sysvmsg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sysvsem | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sysvshm | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| tdlib[*](#special-requirements-for-tdlib) | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| tidy | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| timezonedb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| uopz | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| uuid | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| wddx | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | |
2020-09-21 12:56:26 +00:00
| xdebug | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-30 14:42:57 +00:00
| xhprof | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2021-01-02 20:04:42 +00:00
| xlswriter | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| xmlrpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| xsl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-12-09 08:39:56 +00:00
| yaml | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2021-01-05 14:24:22 +00:00
| yar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2020-09-19 02:59:16 +00:00
| zip | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| zookeeper | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2019-12-17 09:26:35 +00:00
2021-01-05 14:24:22 +00:00
*Number of supported extensions: 92*
2018-04-11 15:39:10 +00:00
<!-- END OF EXTENSIONS TABLE -->
2018-04-12 07:50:14 +00:00
PS: the pre-installed PHP extensions are excluded from this list.
You can list them with the following command (change `php:7.2-cli` to reflect the PHP version you are interested in):
2020-02-21 19:39:09 +00:00
```
$ docker run --rm php:7.2-cli php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
2018-04-12 07:50:14 +00:00
```
2018-04-11 15:39:10 +00:00
## Special requirements
Some extension has special requirements:
<!-- START OF SPECIAL REQUIREMENTS -->
<!-- ########################################################### -->
<!-- # # -->
<!-- # DO NOT EDIT THIS TABLE: IT IS GENERATED AUTOMATICALLY # -->
<!-- # # -->
<!-- # EDIT THE data/special - requirements FILE INSTEAD # -->
<!-- # # -->
<!-- ########################################################### -->
| Extension | Requirements |
2020-03-03 11:08:17 +00:00
|---|---|
2020-09-19 02:59:16 +00:00
| < a name = "special-requirements-for-enchant" ></ a > enchant | • Not available in `7.2-alpine3.12` docker images< br /> • Not available in `7.3-alpine3.12` docker images< br /> • Not available in `7.4-alpine3.12` docker images |
2020-03-03 13:25:40 +00:00
| < a name = "special-requirements-for-parallel" > < / a > parallel | Requires images with PHP compiled with thread-safety enabled (`zts`). |
| < a name = "special-requirements-for-pthreads" > < / a > pthreads | Requires images with PHP compiled with thread-safety enabled (`zts`). |
| < a name = "special-requirements-for-tdlib" ></ a > tdlib | • Not available in `alpine3.7` docker images< br /> • Not available in `jessie` docker images |
2018-04-11 15:39:10 +00:00
<!-- END OF SPECIAL REQUIREMENTS -->
2018-04-12 09:58:21 +00:00
2020-02-21 13:05:53 +00:00
## Tests
When submitting a pull request, a [GitHub Action ](https://github.com/mlocati/docker-php-extension-installer/blob/master/.github/workflows/test-extensions.yml ) is executed to check if affected PHP extensions actually work (see below).
Furthermore, we also check that new versions of extensions in the PECL repository will still work.
This is done on a scheduled basis with another [GitHub Action ](https://github.com/mlocati/docker-php-extension-installer/blob/master/.github/workflows/test-recent-extensions.yml ).
2020-02-22 19:42:50 +00:00
In case of failure, a message is sent to a [Telegram Channel ](https://t.me/docker_php_extension_installer ).
2020-02-21 13:05:53 +00:00
Feel free to subscribe to it to receive failure notifications.
2018-04-12 09:58:21 +00:00
## How to contribute
2019-12-20 17:26:26 +00:00
### Formatting code
Before submitting any pull request, be sure to execute the `lint` script in the `scripts` directory (or `lint.bat` on Windows).
2019-12-17 09:33:20 +00:00
### Adding support to a new PHP extension?
2019-12-11 11:57:53 +00:00
2019-12-17 09:33:20 +00:00
1. change the `install-php-extensions` script
2. update the `data/supported-extensions` file, adding a new line with the handle of the extension and the list of supported PHP versions
3. if the extension requires ZTS images:
add a new line to the `data/special-requirements` file, with the extension handle followed by a space and `zts`
2019-12-17 10:21:01 +00:00
See [this pull request ](https://github.com/mlocati/docker-php-extension-installer/pull/60 ) for an example.
2019-12-17 09:33:20 +00:00
### Changing the supported PHP versions for an already supported PHP extension?
1. change the `install-php-extensions` script
2019-12-18 15:45:20 +00:00
2. update the `data/supported-extensions` file, adding the new PHP version to the existing line corresponding to the updated extension
2019-12-17 10:21:01 +00:00
See [this pull request ](https://github.com/mlocati/docker-php-extension-installer/pull/62 ) for an example.
2019-12-17 09:33:20 +00:00
### Improving code for an already supported extension?
If you change some code that affects one or more extensions, please add a line with `Test: extension1, extension2` to the message of one of the pull request commits.
That way, the test jobs will check the extension even if you don't touch the `data/supported-extensions` file.
Here's an example of a commit message:
```
Improve the GD and ZIP extensions
Test: gd, zip
```
2019-12-18 15:45:20 +00:00
Tests only check the installation of a single PHP extension at a time.
If you want to test installing more PHP extensions at the same time, use a commit message like this:
```
Improve the GD and ZIP extensions
Test: gd+zip
```
2019-12-17 09:33:20 +00:00
If your pull request contains multiple commits, we'll check the "Test:" message of every commit.
If you want to stop parsing next commits, add `-STOP-` in the "Test:" line, for example:
```
Improve the GD and ZIP extensions
Test: gd, zip, -STOP-
```
2019-12-10 07:55:09 +00:00
2019-12-17 10:21:01 +00:00
See [this pull request ](https://github.com/mlocati/docker-php-extension-installer/pull/43 ) for an example.
2019-12-10 07:55:09 +00:00
## Do you want to really say thank you?
You can offer me a [monthly coffee ](https://github.com/sponsors/mlocati ) or a [one-time coffee ](https://paypal.me/mlocati ) :wink: