Sign inSign up

australproject/php

By australproject

•Updated about 2 hours ago

Image
0

3.2K

australproject/php repository overview

⁠Austral Docker PHP 8.1

License Docker Image Version (tag latest semver) Docker Automated build Docker Cloud Build Status Docker Image Size (latest semver)

Base image Alpine 3.17: Docker Hub⁠ or GitHub⁠

⁠Versions

  • PHP: 8.1.16
  • Node: 18.14.2
  • NPM: 9.1.2
  • Squoosh-cli: 0.7.2
  • PostgreSQL-client: 15.2
  • MySQL-client: 10.6.12
  • Supercronic: 0.2.49
  • Xdebug: installed, only loaded when XDEBUG=1

⁠Running as any user (non-root)

The image runs as root or as any UID/GID, for example with Docker Swarm:

services:
  php:
    image: australproject/php:8.1
    user: "3001:3001"

The configuration is rendered at start-up into /tmp/php (writable by any user) from templates stored in the image. When the container is not root, user/group are not set in the FPM pool and chown / su-exec are skipped. Mounted directories must already be writable by the chosen UID.

Quick test:

docker run --rm -u 3001:3001 -e SCRIPT_AUTO=0 australproject/php:8.1 php -i | grep -E "Loaded Configuration|post_max_size"

⁠Environment variables

Application

VariableDefaultDescription
APP_ENVprodprod or dev
APP_DEBUGfalse0/false or 1/true; enables display_errors and E_ALL
XDEBUG01 loads Xdebug 3 (client port 9000)
SCRIPT_AUTO11 runs script-auto/run.sh if it exists. Set 0 on cron and secondary services
CREATE_LOG_DIR01/true creates docker-log/php in the website directory at start-up. Not created by default
CREATE_CACHE_DIR01/true creates var/cache in the website directory at start-up. Not created by default

PHP (php.ini)

VariableDefault
PHP_MEMORY_LIMIT256M
PHP_MAX_EXECUTION_TIME120
PHP_MAX_INPUT_TIME60
PHP_MAX_INPUT_VARS5000
PHP_POST_MAX_SIZE512M
PHP_UPLOAD_MAX_FILESIZE512M
PHP_SESSION_SAVE_PATH/tmp
OPCACHE_ENABLED1
OPCACHE_VALIDATE_TIMESTAMPS1
OPCACHE_MEMORY256 (MB)
OPCACHE_REVALIDATE_FREQ2 (seconds)

OPCACHE_VALIDATE_TIMESTAMPS=0 is only safe for immutable deployments: files edited over SFTP would not be reloaded.

PHP-FPM (pool www)

VariableDefault
FPM_PMdynamic
FPM_MAX_CHILDREN20
FPM_START_SERVERS4
FPM_MIN_SPARE_SERVERS4
FPM_MAX_SPARE_SERVERS16
FPM_MAX_REQUESTS500
FPM_REQUEST_TERMINATE_TIMEOUT300s
FPM_LOG_LEVELnotice

Keep FPM_MAX_CHILDREN × PHP_MEMORY_LIMIT below the container memory limit.

⁠Overriding the configuration

Mount a directory on /overrides (read-only is fine):

Path in /overridesEffect
php.iniReplaces the whole php.ini (copied as is, no variable substitution)
php-fpm.confReplaces the whole php-fpm.conf
www.confReplaces the whole pool configuration
conf.d/*.iniExtra PHP settings, loaded after the base configuration
pool.d/*.confExtra FPM pools, added to the base configuration

For small changes, prefer drop-ins:

; /overrides/conf.d/custom.ini
date.timezone = Europe/Paris
session.save_handler = redis
services:
  php:
    volumes:
      - ./php-overrides:/overrides:ro

⁠Logs

Everything goes to the container output (docker logs): FPM errors, PHP errors (/proc/self/fd/2) and workers' stdout/stderr (catch_workers_output).

⁠Sessions with several replicas

The default /tmp is not shared between replicas. Use a shared store, for example Redis (extension included):

PHP_SESSION_SAVE_PATH=tcp://redis:6379

and add session.save_handler = redis in /overrides/conf.d/.

⁠Script Auto

Add a script-auto/run.sh file in the project path. It runs at container start-up when SCRIPT_AUTO=1 (as www-data when the container is root, as the current user otherwise).

⁠Cron with Supercronic

Supercronic is included and writes job output to stdout/stderr, so it appears in docker logs. Run it in a dedicated service:

services:
  cron:
    image: australproject/php:8.1
    command: supercronic /etc/crontab
    environment:
      - SCRIPT_AUTO=0
    healthcheck:
      disable: true

⁠Healthcheck

The image checks that FPM listens on port 9900. Disable it on services that do not run FPM (cron).

⁠Commit Messages

The commit message must follow the Conventional Commits specification⁠. The following types are allowed:

  • update: Update
  • fix: Bug fix
  • feat: New feature
  • docs: Change in the documentation
  • spec: Spec change
  • test: Test-related change
  • perf: Performance optimization

Examples:

update : Something

fix: Fix something

feat: Introduce X

docs: Add docs for X

spec: Z disambiguation

See License⁠

⁠Credits

Created by Matthieu Beurel⁠. Sponsored by Yipikai Studio⁠.

Tag summary

Content type

Image

Digest

sha256:bd1fa36fc…

Size

123.1 MB

Last updated

about 2 hours ago

docker pull australproject/php:8.1