mydev 89fd137aca feat: add PostgreSQL support with Compose profiles
- Add db-postgres service behind 'postgres' profile (MariaDB moved to 'mariadb' profile)
- Both databases aliased as 'db'; PHP waits for healthy DB (Compose >= 2.20)
- Pass DB_TYPE to the PHP container
- New PHP extensions: pdo_pgsql, gd, bcmath
- Upgrade Node.js to v26.x
- Update README with database selection docs and v1.2.0 changelog
2026-11-01 12:41:43 +02:00
2026-03-19 16:58:25 +02:00
2026-03-22 11:15:56 +02:00

FrankenPHP Docker Environment

A modern, lightweight Docker environment for PHP applications using FrankenPHP, featuring HTTP/2, HTTP/3, automatic HTTPS, and built-in Node.js support for multiple PHP frameworks.

Features

  • 🚀 FrankenPHP Server: Modern PHP server with HTTP/2, HTTP/3, and automatic HTTPS via Caddy
  • 🗄️ Database Support: PostgreSQL or MariaDB — pick one with Docker Compose profiles, both reachable as host db
  • 📦 Node.js Integration: Full Node.js runtime (v26.x) for frontend tooling and build processes
  • 🎯 Multi-Framework Support: Optimized build targets for Laravel, Symfony, Magento2, WordPress, and OpenCart
  • 🧰 CLI Tools Included: Symfony CLI is available for Symfony projects and WP-CLI is included for WordPress workflows
  • 🗄️ Redis Support: A dedicated Redis container is included with health checks and PHP connectivity for supported stacks
  • 📝 PHP 8.0 - 8.5: Support for multiple PHP versions with configurable extensions
  • 🔧 Flexible Configuration: Local, proxy, and production modes
  • 🔒 Automatic HTTPS: Let's Encrypt SSL certificates in production
  • 🎨 Extension-Rich: Pre-installed essential PHP extensions (PDO/MySQL, PDO/PostgreSQL, Redis, APCu, and more)
  • ⚡ Debian Trixie-Based: Lightweight, fast, and efficient container images
  • 🔄 Hot Reload: Automatic code reloading during development

Recently Added

  • PostgreSQL support — choose postgres or mariadb via Docker Compose profiles (COMPOSE_PROFILES), both exposed to the app as host db
  • DB_TYPE environment variable passed to the PHP container so applications can detect the active database
  • pdo_pgsql, gd, and bcmath PHP extensions pre-installed
  • Node.js upgraded to v26.x
  • Health checks for both database services; PHP waits for a healthy database before starting
  • Symfony CLI pre-installed for Symfony-based applications
  • WP-CLI pre-installed for WordPress administration and site management
  • Redis container support with health checks and framework-ready PHP integration
  • Caddy web server with HTTP/2 and HTTP/3 support
  • Automatic HTTPS via Let's Encrypt in production mode
  • Multi-stage Docker builds optimized per framework
  • Alpine-based lightweight container images
  • Built-in health checks for Redis and database services

Requirements

  • Docker Desktop (or Docker Engine + Docker Compose v2.20+; required for optional depends_on entries)
  • 2GB+ RAM available
  • Terminal/Command-line access

Quick Start

1. Clone the Repository

git clone <repository-url>
cd franken

2. Configure Environment

cp .env.example .env

Edit the .env file with your preferred settings:

# Core Configuration
PHP_VERSION=8.4              # PHP version (8.0-8.5)
FRAMEWORK=opencart           # Framework: laravel, symfony, magento2, wordpress, opencart
MODE=proxy                   # Mode: local, prod, proxy
PORT=80                      # Local port
PROJECT_NAME=opencart        # Project name

# Database Configuration (pick one: postgres | mariadb)
COMPOSE_PROFILES=postgres    # Which database container to start
DB_TYPE=postgres             # Passed to the PHP container

# Postgres
POSTGRES_DB=app
POSTGRES_USER=app
POSTGRES_PASSWORD=secret

# MariaDB (used when COMPOSE_PROFILES=mariadb)
MYSQL_ROOT_PASSWORD=rootsecret
MYSQL_DATABASE=app
MYSQL_USER_DATABASE=app
MYSQL_PASSWORD_DATABASE=secret

3. Start Services

docker-compose up -d

4. Access Your Application

Configuration Guide

Environment Variables

Variable Description Options
PHP_VERSION PHP version 8.0, 8.1, 8.2, 8.3, 8.4, 8.5
FRAMEWORK Target framework laravel, symfony, magento2, wordpress, opencart
MODE Run mode local (dev), proxy (behind reverse proxy), prod (production)
PORT HTTP port Any available port (default: 80)
PROJECT_NAME Project identifier Any alphanumeric name
COMPOSE_PROFILES Database service to start postgres or mariadb
DB_TYPE Active database type (passed to the app) postgres or mariadb
POSTGRES_DB Postgres database name app
POSTGRES_USER Postgres user app
POSTGRES_PASSWORD Postgres password Your secure password
MYSQL_ROOT_PASSWORD MariaDB root password Your secure password
MYSQL_DATABASE MariaDB database name app
MYSQL_USER_DATABASE MariaDB user app
MYSQL_PASSWORD_DATABASE MariaDB user password Your secure password
SERVER_NAME Domain (prod mode) Your domain (e.g., example.com)

Database Selection

Both database services run behind Docker Compose profiles, so only the one you enable will start:

  • PostgreSQL: COMPOSE_PROFILES=postgres
  • MariaDB: COMPOSE_PROFILES=mariadb

Keep DB_TYPE in sync (it is passed into the PHP container so your application can detect which database is active). Both services are aliased as db on app-network, so your application always connects to host db regardless of the choice:

# Laravel / generic PDO
DB_CONNECTION=pgsql          # or DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=5432                 # 3306 for MariaDB
DB_DATABASE=app
DB_USERNAME=app
DB_PASSWORD=secret

To switch databases, change the two variables in .env and run:

docker-compose down
docker-compose up -d

Framework-Specific Setup

Laravel

  1. Update .env:

    FRAMEWORK=laravel
    
  2. Uncomment Laravel volume in docker-compose.yml:

    volumes:
      - ./www:/app          # Instead of /app/public
    
  3. Start services:

    docker-compose up -d --build
    

Symfony

  1. Update .env:

    FRAMEWORK=symfony
    
  2. Uncomment Symfony volume in docker-compose.yml:

    volumes:
      - ./www:/app          # Instead of /app/public
    
  3. Build and start:

    docker-compose up -d --build
    

WordPress

  1. Update .env:

    FRAMEWORK=wordpress
    
  2. The default volume mount /app/public works for WordPress

  3. Start services:

    docker-compose up -d --build
    

OpenCart

  1. Update .env:

    FRAMEWORK=opencart
    
  2. Default configuration uses /app/public

  3. Start services:

    docker-compose up -d --build
    

Magento 2

  1. Update .env:

    FRAMEWORK=magento2
    
  2. Start services:

    docker-compose up -d --build
    

Modes Explained

  • local: Development mode with internal TLS disabled, suitable for local development
  • proxy: Designed for use behind a reverse proxy or load balancer
  • prod: Production mode with HTTPS enabled, automatic SSL certificates, and optimized PHP settings

Production Deployment

  1. Update .env:

    MODE=prod
    SERVER_NAME=yourdomain.com
    PHP_VERSION=8.4
    
  2. Enable HTTPS in docker-compose.yml:

    ports:
      - "443:443"           # HTTPS
      - "443:443/udp"       # HTTP/3
    
  3. Start services:

    docker-compose up -d --build
    
  4. FrankenPHP automatically obtains SSL certificates from Let's Encrypt

How to Run

Start Services

# Start in background
docker-compose up -d

# Start with output
docker-compose up

# Start and rebuild images
docker-compose up -d --build

Stop Services

docker-compose down

View Logs

# View all logs
docker-compose logs -f

# View specific service logs
docker-compose logs -f php
docker-compose logs -f db-postgres
docker-compose logs -f db-mariadb

Access Container Shell

# PHP container
docker-compose exec php sh

# Database container (depending on your profile)
docker-compose exec db-postgres psql -U app -d app
docker-compose exec db-mariadb mysql -u app -p

Development Workflow

Running Commands Inside Container

# Composer commands
docker-compose exec php composer install
docker-compose exec php composer require package/name

# NPM/Node commands
docker-compose exec php npm install
docker-compose exec php npm run dev
docker-compose exec php npm run build

# PHP CLI
docker-compose exec php php -v
docker-compose exec php php artisan migrate          # Laravel
docker-compose exec php bin/console doctrine:schema  # Symfony

# Database management
docker-compose exec db-postgres psql -U app -d app    # Postgres
docker-compose exec db-mariadb mysql -u app -p app    # MariaDB

File Structure

franken/
├── docker-compose.yml    # Docker services configuration
├── Dockerfile           # Multi-stage PHP container build
├── .env                 # Environment configuration
├── php.ini             # Custom PHP settings
├── www/                # Web application root
│   └── index.php       # Entry point
└── README.md           # This file

PHP Configuration

Edit php.ini to customize PHP settings:

; Example configurations
display_errors = On
memory_limit = 512M
upload_max_filesize = 100M
post_max_size = 100M

Changes take effect after container restart:

docker-compose restart php

Redis Caching

Setup

Redis is included and pre-configured in docker-compose.yml. It runs in a separate container with:

  • Image: redis:alpine (lightweight, fast)
  • Persistent Storage: Redis data is stored in redis_data volume
  • Health Check: Built-in health check to verify Redis is running
  • Networking: Connected to app-network for internal PHP communication

Redis Service Configuration

Redis is automatically started with docker-compose up. To verify it's running:

# Check Redis container status
docker-compose ps redis

# Connect to Redis CLI
docker-compose exec redis redis-cli

# Test Redis connection from PHP container
docker-compose exec php php -r "
\$redis = new Redis();
\$redis->connect('redis', 6379);
echo 'Redis connected: ' . (\$redis->ping() ? 'OK' : 'FAILED');
\$redis->close();
"

Using Redis in Your Application

Laravel Example

Update your .env:

CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=null

Install/configure in your Laravel app:

# Inside container
docker-compose exec php composer require predis/predis

# Or use PHP's native Redis extension (recommended)

PHP Native Example

<?php
$redis = new Redis();
$redis->connect('redis', 6379);

// Set a cache value
$redis->set('user:1:name', 'John Doe', 3600); // 1 hour TTL

// Get a value
$name = $redis->get('user:1:name');

// Check if key exists
if ($redis->exists('user:1:name')) {
    echo "Key exists";
}

// Delete a key
$redis->del('user:1:name');

// Increment counter
$redis->incr('page_views');

$redis->close();
?>

Symfony Example

Configure in config/packages/cache.yaml:

framework:
  cache:
    default_redis_provider: 'redis://redis:6379'
    pools:
      cache.app:
        adapter: cache.adapter.redis
        provider: 'redis://redis:6379'

WordPress Example

Use a Redis plugin like "Redis Object Cache" and configure:

define('WP_REDIS_HOST', 'redis');
define('WP_REDIS_PORT', 6379);

Common Redis Operations

# Connect to Redis CLI
docker-compose exec redis redis-cli

# Inside redis-cli commands:
PING                                  # Check connection
SET mykey "Hello"                     # Set a key
GET mykey                             # Get a value
DEL mykey                             # Delete a key
KEYS *                                # List all keys
FLUSHDB                               # Clear all keys
INFO                                  # Show Redis info
MONITOR                               # Monitor commands in real-time

Redis Persistence

  • Data persists in the redis_data volume
  • If you need to reset Redis data: docker volume rm gold_redis_data
  • Configure persistence in docker-compose.yml if needed:
redis:
  command: redis-server --appendonly yes  # Enable AOF persistence

Troubleshooting Redis

# Check if Redis is running
docker-compose logs redis

# Restart Redis
docker-compose restart redis

# Clear Redis cache
docker-compose exec redis redis-cli FLUSHDB

# Monitor Redis activity
docker-compose exec redis redis-cli MONITOR

Docker Architecture

Multi-Stage Build

The Dockerfile uses multi-stage builds to optimize for different frameworks:

  • base: Foundation with core PHP extensions
  • node: Adds Node.js runtime
  • laravel: Laravel-specific extensions (Redis, APCu)
  • symfony: Symfony-specific extensions (APCu, Sodium)
  • wordpress: WordPress-specific configuration
  • opencart: OpenCart-specific configuration
  • magento2: Magento 2-specific configuration

Services

PHP Service (FrankenPHP)

  • Image: dunglas/frankenphp:php{PHP_VERSION}-trixie
  • Includes:
    • PHP 8.0-8.5
    • Node.js v26.x
    • Caddy web server
    • Framework-specific extensions

Database Service (PostgreSQL)

  • Profile: postgres (enabled via COMPOSE_PROFILES=postgres)
  • Image: postgres
  • Volume: postgres_data (persistent)
  • Port: 5432 (internal)
  • Network Alias: db — the app connects to host db
  • Health Check: pg_isready

Database Service (MariaDB)

  • Profile: mariadb (enabled via COMPOSE_PROFILES=mariadb)
  • Image: mariadb
  • Volume: mariadb_data (persistent)
  • Port: 3306 (internal)
  • Network Alias: db — the app connects to host db
  • Health Check: healthcheck.sh --connect --innodb_initialized

Redis Service (Cache)

  • Image: redis:alpine (lightweight)
  • Volume: redis_data (persistent)
  • Port: 6379 (internal)
  • Health Check: Built-in Redis ping monitoring
  • Available in all frameworks: Laravel, Symfony, WordPress, OpenCart, Magento2

Network & Volumes

networks:
  app-network:           # Internal communication
    driver: bridge

volumes:
  caddy_data:           # Caddy cache and data
  caddy_config:         # Caddy configuration
  postgres_data:        # PostgreSQL persistence
  mariadb_data:         # MariaDB persistence
  redis_data:           # Redis persistence

PHP Extensions

Core Extensions

  • Database: pdo_mysql, pdo_pgsql, mysqli
  • String: mbstring, ctype, iconv
  • Data: xml, dom, simplexml, fileinfo
  • Security: openssl, tokenizer
  • Utilities: curl, zip, intl, opcache
  • Math & Image: bcmath, gd

Framework-Specific Extensions

All Frameworks (Laravel, Symfony, WordPress, OpenCart, Magento2):

  • redis: Redis cache and session support

Laravel/Magento2:

  • Additional caching optimizations

Symfony:

  • apcu: APCu caching
  • sodium: Modern cryptography

WordPress:

  • Additional compatibility features

Troubleshooting

Port Already in Use

# Change PORT in .env and restart
PORT=8080 docker-compose up -d

Database Connection Issues

Verify credentials in .env and make sure COMPOSE_PROFILES matches the running service:

# Postgres
docker-compose exec php php -r "
\$db = new PDO('pgsql:host=db;port=5432;dbname=app', 'app', 'secret');
echo 'Connected successfully!';
"

# MariaDB
docker-compose exec php php -r "
\$db = new mysqli('db', 'app', 'secret', 'app');
if (\$db->connect_error) exit('Connection failed: ' . \$db->connect_error);
echo 'Connected successfully!';
"

Permission Issues

# Fix permissions in www directory
chmod -R 755 www/

Rebuild Everything

docker-compose down -v
docker-compose up --build -d

Check Container Status

docker-compose ps
docker-compose logs -f

Useful Commands

# List running containers
docker-compose ps

# Restart a service
docker-compose restart php

# Rebuild images
docker-compose build --no-cache

# Execute command in container
docker-compose exec php <command>

# Copy files from container
docker cp <container>:/path/to/file ./local/path

# View resource usage
docker stats

Performance Optimization

For Production

  1. Set MODE=prod in .env
  2. Enable opcache in php.ini:
    opcache.enable=1
    opcache.memory_consumption=256
    
  3. Configure Redis for caching:
    docker-compose exec php redis-cli
    

Database Optimization

  1. Set appropriate POSTGRES_PASSWORD (or MYSQL_ROOT_PASSWORD for MariaDB)
  2. Monitor with:
    # Postgres
    docker-compose exec db-postgres psql -U app -d app -c "SELECT datname, numbackends FROM pg_stat_database;"
    
    # MariaDB
    docker-compose exec db-mariadb mysql -u root -p -e "SHOW PROCESSLIST;"
    

Security Best Practices

  • ✅ Change default database credentials in .env
  • ✅ Use strong passwords for POSTGRES_PASSWORD, MYSQL_ROOT_PASSWORD, and MYSQL_PASSWORD_DATABASE
  • ✅ Set MODE=prod for production deployments
  • ✅ Keep php.ini locked to read-only (default)
  • ✅ Use environment variables for sensitive data
  • ✅ Keep Docker images updated

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Make your changes
  4. Test thoroughly
  5. Commit with clear messages (git commit -am 'Add improvement')
  6. Push to your fork (git push origin feature/improvement)
  7. Open a Pull Request

License

[Specify your license here]

Support & Resources

Changelog

v1.2.0 (Current)

  • PostgreSQL support with COMPOSE_PROFILES=postgres (MariaDB moved behind the mariadb profile)
  • DB_TYPE environment variable exposes the active database type to the PHP container
  • Both database services are network-aliased as db with health checks; PHP waits for a healthy database before starting
  • New PHP extensions: pdo_pgsql, gd, bcmath
  • Node.js upgraded from v20.x to v26.x

v1.1.0

  • Multi-stage Docker build for framework-specific optimization
  • Node.js v20.x integration
  • Support for 5+ PHP frameworks with dedicated configurations
  • Improved documentation and examples
  • Production mode with automatic HTTPS
  • Caddy web server with HTTP/2 and HTTP/3 support
  • Automatic HTTPS via Let's Encrypt in production mode
  • Multi-stage Docker builds optimized per framework
  • Alpine-based lightweight container images
  • Built-in health checks for Redis and database services
  • Symfony CLI and WP-CLI pre-installed for framework-specific workflows
  • Redis container with health checks and PHP connectivity

v1.0.0

  • Initial release with FrankenPHP and MariaDB
  • Basic framework support
  • Development and production modes

Last Updated: November 2026
Maintainer: Development Team

S
Description
No description provided
Readme
76 KiB
0 Stars 0 Watchers 0 Forks
Languages
Dockerfile 99.3%
PHP 0.7%