Production-Ready PHP Docker Images: Solving Common Deployment Pitfalls
The official PHP Docker image lacks Composer, production‑grade security, and runs as root, so most teams fork it and create fragile internal images; serversideup/php builds on the official image by adding environment‑driven configuration, non‑root execution, S6 process management, FrankenPHP support, built‑in health checks, and performance optimizations that deliver up to 484 requests per second versus 68 for the vanilla image.
Problem with the Official PHP Image
The official php:8.3-fpm image only provides a minimal runtime: no Composer, no production‑grade security hardening, runs as root, uses default FPM parameters, and requires custom health‑check scripts. This works for local development but is far from production‑ready.
Project Overview
serversideup/php is an open‑source (GPL‑3.0) Docker image maintained by Dan Pastori and Jay Rogers. It has over 2,500 stars, 1 M+ pulls, 46 contributors, and the latest version v4.5.1 (July 2026). It supports PHP 7.4‑8.5 on both Debian and Alpine bases and offers several variants (cli, fpm, fpm‑nginx, fpm‑apache, frankenphp).
Core Features
Environment‑Variable‑Driven Configuration
Almost every PHP, NGINX, Apache, or Caddy setting can be overridden via an environment variable, eliminating the need to copy or edit configuration files. Example:
services:
php:
image: serversideup/php:8.5-fpm-nginx
environment:
PHP_MEMORY_LIMIT: "512M"
PHP_UPLOAD_MAX_FILE_SIZE: "200M"
PHP_MAX_EXECUTION_TIME: "180"
PHP_OPCACHE_ENABLE: "1"Key variables include PHP_FPM_PM_MAX_CHILDREN, PHP_OPCACHE_JIT, NGINX_CLIENT_MAX_BODY_SIZE, and PHP_FPM_PM_CONTROL (default ondemand for low‑traffic sites).
Non‑Root Execution & Security Hardening
The image runs as www-data (UID 33) by default, limiting the blast radius of a compromise, satisfying Kubernetes PodSecurityPolicy/OPA requirements, and aligning with CIS/NIST baselines. Extensions can be installed during build by temporarily switching to root and using the pre‑installed install-php-extensions helper.
S6 Overlay Process Management
S6 acts as an init system, supervising PHP‑FPM and the web server, providing automatic restarts, graceful shutdowns, and unified logging to STDOUT/STDERR. Behaviour can be tuned with variables such as S6_BEHAVIOUR_IF_STAGE2_FAILS and S6_VERBOSITY.
FrankenPHP Support
The frankenphp variant embeds PHP directly into Caddy, removing the FastCGI overhead. Benefits include architecture simplification, native HTTP/2 & HTTP/3, a worker mode that keeps PHP in memory (significant for Laravel), and community‑reported 2‑3× speed gains. Switching is as simple as changing the image tag.
Quick‑Start Example (Laravel)
Create a minimal project, write a docker‑compose.yml using the fpm‑nginx variant, and run docker compose up. The container listens on port 8080 (non‑privileged) and serves phpinfo() with the configured limits.
Performance Benchmarks
According to Rabbit Company CEO Žiga Zajc, serversideup/php processes about 484 req/s versus 68 req/s for the official image. The gap stems from pre‑tuned OPcache settings, the ondemand FPM process manager, and security hardening that reduces overhead.
Built‑In Health Checks
Web‑server variants expose a /healthcheck endpoint, making Kubernetes livenessProbe and readinessProbe configuration trivial. The path can be overridden with HEALTHCHECK_PATH. CLI and FrankenPHP variants do not expose this endpoint.
Native CloudFlare Support
The fpm‑nginx and fpm‑apache variants ship with a trusted CloudFlare IP list, eliminating the need for manual set_real_ip_from directives.
Suitable Scenarios & Limitations
New or migrated Laravel, WordPress, Symfony projects.
Teams needing consistent dev‑to‑prod environments.
Kubernetes, Docker Swarm, or other orchestration platforms.
CI/CD pipelines that switch PHP versions frequently.
Small‑to‑medium teams wanting to reduce ops overhead.
Limitations include the default non‑standard port 8080, a webroot of /var/www/html/public that may need adjustment, FrankenPHP’s requirement for PHP 8.3+, and the fact that extremely custom NGINX/FPM configurations may still need a custom Dockerfile.
Conclusion
serversideup/php packages scattered best‑practice knowledge into a single, production‑ready image. With a few environment variables and a simple compose.yml, developers obtain a secure, high‑performance PHP runtime without becoming Docker or NGINX experts.
Relevant Links
Project site: https://serversideup.net/open-source/docker-php
GitHub: https://github.com/serversideup/docker-php
Docker Hub: https://hub.docker.com/r/serversideup/php
Documentation: https://serversideup.net/open-source/docker-php/docs/getting-started
Discord community: https://serversideup.net/discord
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
