milejko/php
Flexible PHP Docker image, configurable with ENV, extendable with os-packages
50K+
PHP Docker image with flexibility, and easy configuration in the heart.
Offering Debian Slim, Ubuntu, as well as minimalistic Alpine base, each with three PHP modes: CLI, FPM and Apache.
The Dockerfiles can be found here: https://github.com/milejko/php.
OS choice: Debian Slim Bookworm, Ubuntu Noble, Ubuntu Jammy, Alpine 3
Image variants: CLI, PHP-FPM, Apache2
Supported versions: 7.4, 8.0, 8.1, 8.2, 8.3
Platforms: linux/amd64, linux/arm64, linux/arm/v7
apt-get install phpX.Y-module`
or `apk add phpXY-module`
(Alpine)
PHP-CLI by default runs PHP's interactive shell, but it is also a frontend to php command:
docker run milejko/php:8.2-cli -r 'phpinfo();'
You should be able to see the phpinfo() page in your terminal. Note that php command is missing in the line.
Running other commands (ie. composer) can be acheived like that:
docker run milejko/php:8.2-cli composer
PHP provides a built-in webserver. In the following example we'll create such server.
Dockerfile
FROM milejko/php:8.2-cli
RUN echo "<?php phpinfo();" > /var/www/html/index.php
EXPOSE 8080
CMD [ "php", "-S", "0.0.0.0:8080" ]
Build your image and execute it, using:
docker build -t phpinfo-http .
docker run --publish 127.0.0.1:8080:8080 phpinfo-http
Now after visiting http://127.0.0.1:8080 in your favourite browser, phpinfo() page should be visible.
The example below shows a typical php:8.2-fpm image usage.
Dockerfile
FROM milejko/php:8.2-fpm
RUN echo "<?php phpinfo();" > /var/www/html/index.php
Build your image and execute it, using:
docker build -t phpinfo-fpm .
docker run --env FPM_LOG_LEVEL=debug --publish 127.0.0.1:9000:9000 phpinfo-fpm
Now your PHP-FPM container is up and ready for connections, also take a note that in this example FPM_LOG_LEVEL is
set to "debug".
It is not very useful without a real PHP application mounted (or copied) inside the /var/www/html directory, and nginx with
fastcgi_pass 127.0.0.1:9000;
as a http server, but it definitely runs.
The example below shows a typical php:8.2-apache image usage.
Dockerfile
FROM milejko/php:8.2-apache
RUN echo "<?php phpinfo();" > /var/www/html/index.php
Build your image and execute it, using:
docker build -t phpinfo-apache .
docker run --publish 127.0.0.1:8080:80 phpinfo-apache
Now your Apache container is up and ready for connections, after visiting http://127.0.0.1:8080 in your favourite browser, phpinfo() page should be visible.
amqp
apcu
bcmath
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
random
readline
redis
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xdebug (disabled, see ENV)
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
In this example Imagick module will be added.
First create your own Dockerfile, with this code:
Dockerfile
ARG PHP_VERSION=8.2
FROM milejko/php:${PHP_VERSION}-fpm
RUN apt-get update && \
apt-get install -y php${PHP_VERSION}-imagick
Dockerfile.alpine
FROM milejko/php:8.2-fpm-alpine
RUN apk update && \
apk add --no-cache php82-pecl-imagick
Note that Alpine uses "no-dot" notation for PHP version, and "pecl" prefix for some modules, see the list here: pkgs.alpinelinux.org/packages
After that just build and run your image:
docker build -t fpm-with-imagick .
To tweak those values just pass them by adding --env ENV=value during runtime, or orchestrator configs (ie. docker-compose.yml).
WORKDIR=/var/www/html
ALLOW_URL_FOPEN=1
DEFAULT_SOCKET_TIMEOUT=60
DISPLAY_ERRORS=0
DISPLAY_STARTUP_ERRORS=0
ERROR_REPORTING=E_ALL
MAX_EXECUTION_TIME=30
MEMORY_LIMIT=128M
POST_MAX_SIZE=128M
UPLOAD_MAX_FILESIZE=128M
REALPATH_CACHE_SIZE=4096K
REALPATH_CACHE_TTL=120
OPCACHE_ENABLE=1
OPCACHE_CLI_ENABLE=0
OPCACHE_MEMORY_CONSUMPTION=128M
OPCACHE_INTERNED_STRINGS_BUFFER=16
OPCACHE_VALIDATE_TIMESTAMPS=1
OPCACHE_REVALIDATE_FREQ=2
OPCACHE_PRELOAD=
OPCACHE_PRELOAD_USER=
OPCACHE_JIT=off
OPCACHE_JIT_BUFFER_SIZE=0
XDEBUG_ENABLE=0
XDEBUG_MODE=off
FPM_LISTEN_PORT=9000
FPM_LOG_LEVEL=notice
FPM_PM_MAX_CHILDREN=90
FPM_PM_START_SERVERS=10
FPM_PM_MIN_SPARE_SERVERS=4
FPM_PM_MAX_SPARE_SERVERS=16
FPM_PM_MAX_REQUESTS=0
APACHE_LISTEN_PORT=80
APACHE_SERVER_NAME=localhost
APACHE_TIMEOUT=300
APACHE_KEEPALIVE=On
APACHE_MAX_KEEPALIVE_REQUESTS=100
APACHE_KEEPALIVE_TIMEOUT=5
APACHE_LOG_LEVEL=warn
docker pull milejko/php