π Laravel Docker Production Stack
Production-ready Docker environment for Laravel 12+ with automated deployment, SSL management, and Cloudflare detection.
π Table of Contents
π― Why This Stack?
This stack started as a personal setup that evolved over several years of Laravel deployments. It tries to address common pain points and provide sensible defaults out of the box.
What it offers:
- Zero-config deployment β One command deploys dev or production
- Security defaults β SSH hardening, Fail2Ban, UFW firewall, automated updates
- SSL automation β Let's Encrypt with auto-renewal via Certbot
- Smart Cloudflare detection β Automatically adapts to proxy/DNS-only mode
- Production optimizations β OPcache, Redis caching, optimized PHP-FPM
- Real-time features β Horizon for queues, supervisor for workers
- Developer experience β Hot reload with Vite, interactive scripts
If it can save you some setup time, that's great. Feel free to adapt it to your needs.
β¨ Features
π§ Core Stack
- Laravel 12+ with PHP 8.4+
- Nginx with optimized configuration & security headers
- MySQL 8.0 with custom tuning
- Redis 7 for cache/sessions/queues
- Horizon for queue management
- Supervisor for background workers
- Certbot for SSL certificate management
π Automation Scripts
deploy.shβ Interactive deployment (dev/prod)server-setup.shβ One-time server initializationupdate.shβ Update after git pullbackup.shβ Database backupslaravel-helper.shβ Quick Laravel commandscreate-ssl-certs.shβ Dev SSL certificates
π Security
- SSH hardening (key-only auth, root disabled)
- Fail2Ban protection (automatic IP banning)
- UFW firewall (ports 22, 80, 443)
- Automated security updates
- Nginx rate limiting & security headers
- Sensitive file protection (.env, .git)
π Production Ready
- Cloudflare detection (proxy vs DNS-only)
- Health checks on all services
- Resource limits (CPU/memory)
- Zero-downtime deployments
- Comprehensive logging
- Graceful shutdowns
β‘ Quick Start
1οΈβ£ First-Time Server Setup
Run this once on a fresh Ubuntu server (as root):
curl -fsSL https://raw.githubusercontent.com/mg2k4/Dockavel/main/scripts/server-setup.sh | sudo bash
This configures Docker, firewall, Fail2Ban, deploy user, and security hardening.
β±οΈ Duration: ~5 minutes
2οΈβ£ Deploy Application
SSH into your server as the deploy user:
ssh deploy@your-server-ip
cd /var/www
git clone git@github.com:mg2k4/Dockavel.git app
cd app
Development:
./scripts/deploy.sh dev
Production:
./scripts/deploy.sh prod
The script handles everything: environment setup, Docker build, dependencies, SSL, migrations, and optimization.
β±οΈ Duration: ~3-5 minutes (first deploy)
3οΈβ£ Access Your Application
Development:
http://localhost (HTTP)
https://localhost (HTTPS, self-signed)
http://localhost:5173 (Vite HMR)
Production:
https://your-domain.com (with Let's Encrypt SSL)
ποΈ Architecture
Docker Services
| Service | Purpose | Exposed Ports |
|---|---|---|
app |
PHP-FPM + Laravel application | - |
webserver |
Nginx reverse proxy | 80, 443 |
db |
MySQL 8.0 database | 3306 (dev) |
caching |
Redis for cache/session/queue | 6379 (dev) |
supervisor |
Horizon + background workers | - |
scheduler |
Laravel task scheduler (cron) | - |
certbot |
SSL certificate management | - |
See Docker Architecture for detailed service configurations.
π Documentation
Core Documentation
- Installation Guide β Detailed setup instructions
- Scripts Reference β All automation scripts explained
- Docker Architecture β Deep dive into containers
- Troubleshooting β Common issues and solutions
- Contributing β Contribution guidelines
π¦ Requirements
Server: Ubuntu 20.04+, 2GB RAM minimum Local: Docker Desktop, Git
See Installation Guide for full details.
π¦ Common Commands
Deployment
./scripts/deploy.sh dev # Deploy development
./scripts/deploy.sh prod # Deploy production
./scripts/update.sh # Update after git pull
Container Management
docker compose ps # List containers
docker compose logs -f # Follow all logs
docker compose logs -f app # Follow app logs
docker compose exec app bash # Shell into app
docker compose restart # Restart services
docker compose down # Stop services
Laravel Commands
./scripts/laravel-helper.sh # Interactive menu
docker compose exec app php artisan migrate
docker compose exec app php artisan queue:work
docker compose exec app php artisan horizon
Database
./scripts/backup.sh # Backup database
docker compose exec db mysql -u root -p
π Updates
cd /var/www/app
git pull origin main
./scripts/update.sh
See Scripts Reference for more commands.
π€ Contributing
All contributions are welcome! Whether it's fixing a typo, improving docs, or adding features β everything helps.
See Contributing Guidelines for details.
π License
MIT License β Copyright (c) 2026 mg2k4
See LICENSE for full text.
π Acknowledgments
- Laravel β The PHP framework for web artisans
- Docker β Containerization platform
- Nginx β High-performance web server
- Let's Encrypt β Free SSL certificates
- Cloudflare β CDN and DDoS protection
π¬ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
πΊοΈ Roadmap
Some ideas for future versions, time permitting:
v1.1
- Automated backup to S3/DigitalOcean Spaces
- Monitoring with Prometheus/Grafana
- GitHub Actions CI/CD templates
v2.0
- Kubernetes deployment manifests
- PostgreSQL support
- Multi-region setup guide
PRs are welcome if you want to tackle any of these!
Shared hoping it might be useful to someone