Skip to content

Commit

Permalink
feat: disable extensions support for 8.1, 8.2 & add extensions list
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Oct 19, 2024
1 parent 5e721b7 commit c9001ce
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 5 deletions.
68 changes: 68 additions & 0 deletions 8.1-fpm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
46 changes: 46 additions & 0 deletions 8.1-fpm/extensions.txt
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions 8.2-fpm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
46 changes: 46 additions & 0 deletions 8.2-fpm/extensions.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion 8.3-fpm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ if [[ $extensions_count -gt 0 ]]; then
fi
done

echo
echo "Verifying PHP extensions..."

php -v
Expand Down Expand Up @@ -78,6 +77,7 @@ if [[ $extensions_count -gt 0 ]]; then
fi

echo "Tests were successful!"
echo
fi

exec "$@"
44 changes: 44 additions & 0 deletions 8.3-fpm/extensions.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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 '<?php phpinfo();' > index.php; php -S [::]:80 -t ."
docker run --rm
# Or
docker run --rm -p 8088:80 joseluisq/php-fpm:8.2 sh -c "echo '<?php phpinfo();' > index.php; php -S [::]:80 -t ."
# Or
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c9001ce

Please sign in to comment.