From c9001cecb833a19f6ded338fd970afca2f36c087 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sat, 19 Oct 2024 23:24:20 +0200 Subject: [PATCH] feat: disable extensions support for 8.1, 8.2 & add extensions list --- 8.1-fpm/entrypoint.sh | 68 ++++++++++++++++++++++++++++++++++++++++++ 8.1-fpm/extensions.txt | 46 ++++++++++++++++++++++++++++ 8.2-fpm/entrypoint.sh | 68 ++++++++++++++++++++++++++++++++++++++++++ 8.2-fpm/extensions.txt | 46 ++++++++++++++++++++++++++++ 8.3-fpm/entrypoint.sh | 2 +- 8.3-fpm/extensions.txt | 44 +++++++++++++++++++++++++++ README.md | 10 ++++--- 7 files changed, 279 insertions(+), 5 deletions(-) create mode 100644 8.1-fpm/extensions.txt create mode 100644 8.2-fpm/extensions.txt create mode 100644 8.3-fpm/extensions.txt diff --git a/8.1-fpm/entrypoint.sh b/8.1-fpm/entrypoint.sh index 94a440b..f6b68ea 100755 --- a/8.1-fpm/entrypoint.sh +++ b/8.1-fpm/entrypoint.sh @@ -12,4 +12,72 @@ if [[ -n "$ENV_SUBSTITUTION_ENABLE" ]] && [[ "$ENV_SUBSTITUTION_ENABLE" = "true" /envsubst.sh fi +# Disable PHP extensions on demand +extensions=${PHP_DISABLE_EXTENSIONS//[[:blank:]]/} +extensions=${extensions//,/ } +extensions_count=$(echo $extensions | grep -o " " | wc -l) + +if [[ -n "$extensions" ]]; then extensions_count=$((extensions_count + 1)); fi + +if [[ $extensions_count -gt 0 ]]; then + echo "Disabling $extensions_count extension(s): $(echo $extensions)" + + ext_dir=$(php -r 'echo ini_get("extension_dir");') + for ext in $extensions; do + disabled=0 + + ext_file="$ext_dir/$ext.so" + if [[ -f "$ext_file" ]]; then + mv -f $ext_file "$ext_file.disabled" + disabled=1 + fi + + ext_file_ini=${PHP_INI_DIR}/conf.d/docker-php-ext-$ext.ini + if [[ -f "$ext_file_ini" ]]; then + mv -f $ext_file_ini "$ext_file_ini.disabled" + disabled=1 + fi + + if [[ "$disabled" = 1 ]]; then + echo "OK: '$ext' disabled" + fi + done + + echo "Verifying PHP extensions..." + + php -v + php-fpm --test + + PHP_ERROR="$(php -v 2>&1 1>/dev/null)" + + if [ -n "${PHP_ERROR}" ]; then + echo "${PHP_ERROR}" + false + fi + + PHP_ERROR="$(php -i 2>&1 1>/dev/null)" + + if [ -n "${PHP_ERROR}" ]; then + echo "${PHP_ERROR}" + false + fi + + PHP_FPM_ERROR="$(php-fpm -v 2>&1 1>/dev/null)" + + if [ -n "${PHP_FPM_ERROR}" ]; then + echo "${PHP_FPM_ERROR}" + false + fi + + PHP_FPM_ERROR="$(php-fpm -i 2>&1 1>/dev/null)" + + if [ -n "${PHP_FPM_ERROR}" ]; then + echo "${PHP_FPM_ERROR}" + false + fi + + echo "Tests were successful!" + echo +fi + exec "$@" diff --git a/8.1-fpm/extensions.txt b/8.1-fpm/extensions.txt new file mode 100644 index 0000000..37945be --- /dev/null +++ b/8.1-fpm/extensions.txt @@ -0,0 +1,46 @@ +amqp +apcu +bcmath +bz2 +exif +gd +gettext +gmp +igbinary +imagick +imap +intl +lz4 +memcache +mongodb +msgpack +mysqli +oauth +opcache +pcntl +pdo_dblib +pdo_mysql +pdo_pgsql +pdo_sqlsrv +pgsql +phalcon +psr +rdkafka +redis +soap +sockets +sodium +sqlsrv +ssh2 +swoole +sysvmsg +sysvsem +sysvshm +tidy +uuid +vips +xdebug +xsl +yaml +zip +zstd diff --git a/8.2-fpm/entrypoint.sh b/8.2-fpm/entrypoint.sh index 94a440b..f6b68ea 100755 --- a/8.2-fpm/entrypoint.sh +++ b/8.2-fpm/entrypoint.sh @@ -12,4 +12,72 @@ if [[ -n "$ENV_SUBSTITUTION_ENABLE" ]] && [[ "$ENV_SUBSTITUTION_ENABLE" = "true" /envsubst.sh fi +# Disable PHP extensions on demand +extensions=${PHP_DISABLE_EXTENSIONS//[[:blank:]]/} +extensions=${extensions//,/ } +extensions_count=$(echo $extensions | grep -o " " | wc -l) + +if [[ -n "$extensions" ]]; then extensions_count=$((extensions_count + 1)); fi + +if [[ $extensions_count -gt 0 ]]; then + echo "Disabling $extensions_count extension(s): $(echo $extensions)" + + ext_dir=$(php -r 'echo ini_get("extension_dir");') + for ext in $extensions; do + disabled=0 + + ext_file="$ext_dir/$ext.so" + if [[ -f "$ext_file" ]]; then + mv -f $ext_file "$ext_file.disabled" + disabled=1 + fi + + ext_file_ini=${PHP_INI_DIR}/conf.d/docker-php-ext-$ext.ini + if [[ -f "$ext_file_ini" ]]; then + mv -f $ext_file_ini "$ext_file_ini.disabled" + disabled=1 + fi + + if [[ "$disabled" = 1 ]]; then + echo "OK: '$ext' disabled" + fi + done + + echo "Verifying PHP extensions..." + + php -v + php-fpm --test + + PHP_ERROR="$(php -v 2>&1 1>/dev/null)" + + if [ -n "${PHP_ERROR}" ]; then + echo "${PHP_ERROR}" + false + fi + + PHP_ERROR="$(php -i 2>&1 1>/dev/null)" + + if [ -n "${PHP_ERROR}" ]; then + echo "${PHP_ERROR}" + false + fi + + PHP_FPM_ERROR="$(php-fpm -v 2>&1 1>/dev/null)" + + if [ -n "${PHP_FPM_ERROR}" ]; then + echo "${PHP_FPM_ERROR}" + false + fi + + PHP_FPM_ERROR="$(php-fpm -i 2>&1 1>/dev/null)" + + if [ -n "${PHP_FPM_ERROR}" ]; then + echo "${PHP_FPM_ERROR}" + false + fi + + echo "Tests were successful!" + echo +fi + exec "$@" diff --git a/8.2-fpm/extensions.txt b/8.2-fpm/extensions.txt new file mode 100644 index 0000000..37945be --- /dev/null +++ b/8.2-fpm/extensions.txt @@ -0,0 +1,46 @@ +amqp +apcu +bcmath +bz2 +exif +gd +gettext +gmp +igbinary +imagick +imap +intl +lz4 +memcache +mongodb +msgpack +mysqli +oauth +opcache +pcntl +pdo_dblib +pdo_mysql +pdo_pgsql +pdo_sqlsrv +pgsql +phalcon +psr +rdkafka +redis +soap +sockets +sodium +sqlsrv +ssh2 +swoole +sysvmsg +sysvsem +sysvshm +tidy +uuid +vips +xdebug +xsl +yaml +zip +zstd diff --git a/8.3-fpm/entrypoint.sh b/8.3-fpm/entrypoint.sh index c643873..f6b68ea 100755 --- a/8.3-fpm/entrypoint.sh +++ b/8.3-fpm/entrypoint.sh @@ -43,7 +43,6 @@ if [[ $extensions_count -gt 0 ]]; then fi done - echo echo "Verifying PHP extensions..." php -v @@ -78,6 +77,7 @@ if [[ $extensions_count -gt 0 ]]; then fi echo "Tests were successful!" + echo fi exec "$@" diff --git a/8.3-fpm/extensions.txt b/8.3-fpm/extensions.txt new file mode 100644 index 0000000..c109893 --- /dev/null +++ b/8.3-fpm/extensions.txt @@ -0,0 +1,44 @@ +amqp +apcu +bcmath +bz2 +exif +gd +gettext +gmp +igbinary +imap +intl +lz4 +memcache +mongodb +msgpack +mysqli +oauth +opcache +pcntl +pdo_dblib +pdo_mysql +pdo_pgsql +pdo_sqlsrv +pgsql +psr +rdkafka +redis +soap +sockets +sodium +sqlsrv +ssh2 +swoole +sysvmsg +sysvsem +sysvshm +tidy +uuid +vips +xdebug +xsl +yaml +zip +zstd diff --git a/README.md b/README.md index f0c01d5..8f3b928 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ However, you can still find legacy versions like `7.4.x` or `8.0.x` on [Releases |   |   |   |   | | **Others** | | | | | composer | v2.7 | v2.7 | v2.7 | +|   |   |   |   | +| **Extensions file** | [8.1-fpm/extensions.txt](8.1-fpm/extensions.txt) | [8.2-fpm/extensions.txt](8.2-fpm/extensions.txt) | [8.3-fpm/extensions.txt](8.3-fpm/extensions.txt) | **Footnotes** @@ -132,7 +134,7 @@ FROM joseluisq/php-fpm:8.1 To give a Docker image a quick try, just execute any of those commands and then navigate to [localhost:8088](http://localhost:8088) ```sh -docker run --rm -p 8088:80 joseluisq/php-fpm:8.3 sh -c "echo ' index.php; php -S [::]:80 -t ." +docker run --rm # Or docker run --rm -p 8088:80 joseluisq/php-fpm:8.2 sh -c "echo ' index.php; php -S [::]:80 -t ." # Or @@ -181,11 +183,11 @@ Settings replaced into `/usr/local/etc/php/conf.d/default-php.ini` file (`php.in - `PHP_EXPOSE_PHP=On` - `PHP_SESSION_GC_MAXLIFETIME=1440` -### Disable PHP extensions +### Disable PHP additional extensions -The PHP extensions can be disabled at startup by providing the `PHP_DISABLE_EXTENSIONS` environment variable with one or more names. For example `PHP_DISABLE_EXTENSIONS=psr,exif,bz2`. +The PHP additional extensions can be disabled at startup by providing the `PHP_DISABLE_EXTENSIONS` environment variable with one or more names. For example `PHP_DISABLE_EXTENSIONS=psr,exif,bz2`. -Find the valid extension names by using `php -m`. For example `docker run --rm joseluisq/php-fpm:8.3 php -m | grep "exif". +Find the valid extension names at `extensions.txt` file of every PHP version or by using `php -m`. For example `docker run --rm joseluisq/php-fpm:8.3 php -m | grep "exif"`. ## Docker Compose examples