
Secure and Lightweight PHP Production Stack with Docker (PHP-FPM + Nginx)
Deploying modern PHP applications like WordPress, Laravel, or custom stacks requires a secure, fast, and production-grade infrastructure. Thatβs where the php-production-stack
comes in β a Docker-based, production-ready PHP-FPM + Nginx container built on Alpine Linux. This stack is optimized for performance, portability, and real-world deployment scenarios.
βοΈ Why Use This Stack?
Whether youβre deploying on AWS, a VPS, or locally on M1/M2 Macs, this image supports both ARM64 and AMD64 architectures, ensuring wide compatibility. It includes all the essential PHP extensions, a secure Nginx configuration, and a lightweight Alpine base.
Stack Components Overview
- PHP 8.2 (FPM) with extensive extension support
- Nginx optimized for HTTP/1.1, Gzip compression, and static caching
- Multi-arch support: Apple Silicon, AWS Graviton, Intel
- Custom entrypoint to supervise PHP-FPM and Nginx
- Logs are Docker-native: routed to
stdout
andstderr
- Security: runs as a non-root user with minimal permissions
π Default Directory Structure
/var/www/html # Default document root
For Laravel-style projects, you can switch to /var/www/html/public
easily by adjusting the Nginx config.
β Extensions Installed by Default
pdo
,pdo_mysql
,mysqli
,mbstring
,curl
,json
,xml
fileinfo
,dom
,phar
,iconv
,zip
,tokenizer
simplexml
,intl
,exif
,soap
,bcmath
gd
,imagick
,opcache
,redis
,xdebug
Need more? Add custom extensions in your Dockerfile:
RUN install-php-extensions pcntl zip imagick
Getting Started
πΉ Pull the Prebuilt Image
docker pull ghcr.io/nooblk-98/php-docker-nginx:php82
πΉ Run the Container
docker run -d -p 80:80 ghcr.io/nooblk-98/php-docker-nginx:php82
Mount your local project:
docker run -d -p 80:80 -v $(pwd):/var/www/html ghcr.io/nooblk-98/php-docker-nginx:php82
πΉ Use as a Base Image
FROM ghcr.io/nooblk-98/php-docker-nginx:php82
COPY . /var/www/html
π§ Configuration Details
Nginx Config
Path: /etc/nginx/nginx.conf
To set Laravelβs /public
as root:
RUN sed -i 's|root /var/www/html;|root /var/www/html/public;|' /etc/nginx/nginx.conf
Entrypoint Script
#!/bin/sh
echo "Starting PHP-FPM..."
php-fpm -D
echo "Starting Nginx..."
exec nginx -g "daemon off;"
Build from Source
docker build -t wp-production-stack .
docker run -d -p 80:80 wp-production-stack
Why This Stack is Production-Ready
- β Alpine Linux for a minimal footprint
- β Non-root execution for security
- β Opcache, Gzip, and Redis support
- β Scalable in Dockerized environments
- β Multi-arch support (ARM + AMD)