docker.recipes

FrankenPHP

beginner

Modern PHP app server built on Caddy with automatic HTTPS.

Overview

FrankenPHP is a revolutionary PHP application server that combines the power of Go's Caddy web server with PHP's CGO bindings, creating a modern alternative to traditional PHP-FPM and Apache setups. Built by Kévin Dunglas, FrankenPHP eliminates the overhead of spawning new PHP processes for each request by keeping PHP workers in memory, similar to Swoole or RoadRunner, while maintaining full compatibility with existing PHP applications. The server includes Caddy's automatic HTTPS provisioning through Let's Encrypt, HTTP/3 support, and implements cutting-edge features like 103 Early Hints for improved performance. This Docker configuration leverages FrankenPHP's worker mode capabilities to serve PHP applications with dramatically reduced latency and increased throughput compared to traditional setups. The integration with Caddy provides zero-configuration HTTPS, automatic certificate management, and modern HTTP protocol support out of the box. FrankenPHP's unique architecture allows it to handle thousands of concurrent connections while consuming significantly less memory than conventional PHP deployment methods. Development teams building high-performance PHP applications, Laravel and Symfony projects requiring enterprise-grade performance, and organizations seeking to modernize their PHP infrastructure will benefit most from this setup. FrankenPHP is particularly valuable for applications that need real-time features, WebSocket support, or handle high concurrent loads, making it ideal for modern web applications, APIs, and microservices that demand both performance and simplicity.

Key Features

  • Worker mode keeps PHP processes in memory for lightning-fast response times without process spawning overhead
  • Native Laravel Octane and Symfony Runtime integration for zero-configuration framework optimization
  • HTTP/3 and HTTP/2 support with server push capabilities for improved client performance
  • 103 Early Hints implementation allows browsers to preload resources before full response
  • Automatic HTTPS certificate provisioning and renewal through Let's Encrypt integration
  • Real-time WebSocket support built directly into the PHP runtime without external dependencies
  • Graceful worker reloading enables zero-downtime deployments and configuration changes
  • Built-in request/response pooling reduces garbage collection pressure and memory allocations

Common Use Cases

  • 1High-traffic Laravel applications requiring sub-millisecond response times with Octane integration
  • 2Real-time web applications needing WebSocket connections for chat, notifications, or live updates
  • 3API-heavy microservices architecture where PHP service performance is critical
  • 4E-commerce platforms handling thousands of concurrent users during peak shopping periods
  • 5Content management systems requiring fast page generation with automatic HTTPS
  • 6Development environments where quick iteration and hot-reloading improve productivity
  • 7SaaS applications needing enterprise-grade performance without complex infrastructure setup

Prerequisites

  • Docker Engine 20.10+ and Docker Compose 2.0+ for container orchestration support
  • Minimum 512MB RAM available for FrankenPHP worker processes and Caddy operations
  • Ports 80 and 443 available on host system for HTTP/HTTPS traffic handling
  • Basic understanding of Caddyfile syntax for server configuration and routing rules
  • PHP application structure with public directory containing index.php entry point
  • Domain name with proper DNS configuration if using automatic HTTPS certificates

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 frankenphp:
3 image: dunglas/frankenphp:latest
4 container_name: frankenphp
5 restart: unless-stopped
6 volumes:
7 - ./app:/app/public
8 - ./Caddyfile:/etc/caddy/Caddyfile:ro
9 ports:
10 - "80:80"
11 - "443:443"
12 networks:
13 - franken-network
14
15networks:
16 franken-network:
17 driver: bridge

.env Template

.env
1# FrankenPHP with Caddy

Usage Notes

  1. 1Docs: https://frankenphp.dev/docs/
  2. 2Built on Caddy - automatic HTTPS with Let's Encrypt
  3. 3Worker mode keeps PHP in memory (like Swoole/RoadRunner)
  4. 4103 Early Hints support for faster page loads
  5. 5Native support for Laravel, Symfony - just works
  6. 6Configure with Caddyfile: php_server directive

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 frankenphp:
5 image: dunglas/frankenphp:latest
6 container_name: frankenphp
7 restart: unless-stopped
8 volumes:
9 - ./app:/app/public
10 - ./Caddyfile:/etc/caddy/Caddyfile:ro
11 ports:
12 - "80:80"
13 - "443:443"
14 networks:
15 - franken-network
16
17networks:
18 franken-network:
19 driver: bridge
20EOF
21
22# 2. Create the .env file
23cat > .env << 'EOF'
24# FrankenPHP with Caddy
25EOF
26
27# 3. Start the services
28docker compose up -d
29
30# 4. View logs
31docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/frankenphp/run | bash

Troubleshooting

  • Worker process crashes with memory errors: Increase container memory limits and tune PHP memory_limit setting in worker mode
  • Automatic HTTPS fails with certificate errors: Verify domain DNS points to server and ports 80/443 are publicly accessible
  • PHP application returns 502 errors: Check that app directory contains valid PHP files and public/index.php entry point exists
  • WebSocket connections fail to establish: Ensure Caddyfile includes proper WebSocket upgrade directives and routing
  • High memory usage in worker mode: Implement worker recycling strategies and tune FRANKENPHP_WORKER environment variables
  • Static assets not serving correctly: Verify Caddyfile file_server directives and check volume mount paths match application structure

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space