Sign inSign up

sunasteriskrnd/php

By sunasteriskrnd

•Updated over 3 years ago

PHP image with support for PostgreSQL, MySQL & some common extensions

Image
1

50K+

sunasteriskrnd/php repository overview

⁠PHP Docker Image

PHP images based on the official image⁠ with support for PostgreSQL, MySQL, some common extensions & configurable via environment variables.

Docker Cloud Build Status

⁠Available tags

These are all available tags divided into six variants⁠.

⁠Installed extensions

The following extra PHP extensions are installed.

  • bcmath
  • gd (with JPEG support)
  • mysqli
  • opcache
  • pdo_mysql
  • pgsql
  • pdo_pgsql
  • redis
  • zip

You may install more extensions using the same method used with the official PHP image⁠.

⁠Configuration

Configuration via environment variables is supported. Environment variables prefixed with PHP. are set as PHP configurations. Environment variables prefixed with PHP_FPM. are set as configuration for the www pool (fpm and nginx variants only). For example:

docker run --rm -it \
    -e PHP.memory_limit=256M \
    -e PHP.post_max_size=64M \
    -e PHP.upload_max_file_size=64M \
    sunasteriskrnd/php
docker run --rm -it \
    -e PHP.memory_limit=256M \
    -e PHP_FPM.pm=ondemand \
    -e PHP_FPM.pm.max_children=40 \
    sunasteriskrnd/php:fpm

Or you can use the original method⁠ as used with the official image.

⁠PHP-FPM Healthcheck

Healthcheck for php-fpm image is included as a script php-fpm-healthcheck.

docker run --rm -d  \
    --health-cmd=php-fpm-healthcheck \
    --health-interval=15s \
    --health-timeout=3s \
    --health-retries=3 \
    sunasteriskrnd/php:fpm

Using docker-compose:

healthcheck:
  test: ["CMD", "php-fpm-healthcheck"]
  interval: 15s
  timeout: 3s
  retries: 3

⁠Image variants

There are 3 variants (PHP CLI, PHP-FPM, Nginx) based on Alpine and Debian buster to fit your specific use cases. Default images are based on Alpine⁠ for minimal image size. You can use the Debian variant if you need support for glibc dependent packages/extensions.

Docker tags follow the pattern sunasteriskrnd/php:<version>-<variant>-<base>. <variant> is either cli, fpm, or nginx. <base> is either alpine or buster (current Debian suite). Omiting <version> or <base> will make them the default values (PHP 7.4 on Alpine).

⁠sunasteriskrnd/php:<version>-cli

PHP CLI image, based on php:<version>-cli⁠ image.

⁠sunasteriskrnd/php:<version>-fpm

PHP CLI image, based on php:<version>-fpm⁠ image.

⁠sunasteriskrnd/php:<version>-nginx

This image contains the Nginx webserver to serve your PHP application.

⁠Usage

Assuming you are in the directory containing your index.php file. Run this command to create a container to serve your application on port 80.

docker run -d -p 80:80 -v "$PWD":/var/www/html sunasteriskrnd/php:7.4-nginx
⁠Using a Dockerfile

Assuming src/ is the directory containing your PHP code with an index.php file. You can use the nginx variant as base image for your image as below.

FROM sunasteriskrnd/php:7.4-nginx

COPY src/ /var/www/html/
⁠Changing default nginx root

By default, the nginx image serves from /var/www/html directory. If you wish to change this location, specify the DOCUMENT_ROOT environment variable. For example, to change the root to /srv/application, your Dockerfile may look like this:

FROM sunasteriskrnd/php:7.4-nginx

ENV DOCUMENT_ROOT=/srv/application

COPY src/ /srv/application

Tag summary

Content type

Image

Digest

sha256:9454fc1ce…

Size

35.3 MB

Last updated

over 3 years ago

docker pull sunasteriskrnd/php:alpine3.16