GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - serwin35/docker-laravel-starter: Production-ready Laravel Docker Starter Kit โ€” PHP 8.4, Nginx, MySQL/PostgreSQL, Redis, CI/CD with releases & rollback

BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
.docker
.docker
 
 
.github
.github
 
 
scripts
scripts
 
 
.dockerignore
.dockerignore
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
QUICKSTART.md
QUICKSTART.md
 
 
README.md
README.md
 
 
docker-compose.dev.yml
docker-compose.dev.yml
 
 
docker-compose.prod.yml
docker-compose.prod.yml
 
 
docker-compose.staging.yml
docker-compose.staging.yml
 
 
docker-compose.yml
docker-compose.yml
 
 

Repository files navigation

๐Ÿ‹ Laravel Docker Starter Kit

Production-ready Docker environment for Laravel โ€” dev, staging and prod in one place.

Stars Forks Issues PRs Welcome License

PHP Laravel Nginx MySQL PostgreSQL Redis


โœจ Why This Starter Kit?

A complete, battle-tested Docker setup that goes further than Laravel Sail:

Feature Laravel Sail This starter
Dev environment โœ… โœ…
Staging environment โŒ โœ…
Production environment โŒ โœ…
Multi-stage Dockerfile (dev/prod) โŒ โœ…
CI/CD with GitHub Actions โŒ โœ…
Dynamic .env from GitHub Environments โŒ โœ…
Releases system + rollback โŒ โœ…
MySQL 8.4 or PostgreSQL 16 (switchable) โœ… โœ…
Xdebug 3 pre-configured โŒ โœ…
Opcache + JIT in production โŒ โœ…
Mailpit (fake SMTP) โœ… โœ…
MinIO (local S3-compatible storage) โŒ โœ…
Laravel Reverb (WebSocket server) โŒ โœ…
SSL/HTTPS + cert generator โŒ โœ…
Queue worker + Scheduler โŒ โœ…
Security headers in Nginx โŒ โœ…

๐Ÿงฑ Stack

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Nginx (stable)                โ”‚
โ”‚         Security headers ยท Gzip ยท Cache          โ”‚
โ”‚         HTTP + HTTPS (app-ssl.conf)              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ FastCGI
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               PHP 8.4-FPM (Alpine)               โ”‚
โ”‚    Extensions: gd, intl, bcmath, redis, ...      โ”‚
โ”‚    DEV:  Xdebug 3                                โ”‚
โ”‚    PROD: Opcache + JIT + entrypoint cache        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚                  โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ MySQL 8.4      โ”‚  โ”‚  Redis 7                      โ”‚
โ”‚  OR            โ”‚  โ”‚  Cache ยท Queue ยท Sessions     โ”‚
โ”‚ PostgreSQL 16  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ (via profiles) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”€โ”€ DEV only (via profiles) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Mailpit (SMTP)  ยท  MinIO (S3)  ยท  Reverb (WS)
Queue Worker    ยท  Scheduler   ยท  Vite dev server

๐Ÿ“ฆ Directory Structure

.
โ”œโ”€โ”€ .docker/
โ”‚   โ”œโ”€โ”€ php/
โ”‚   โ”‚   โ”œโ”€โ”€ Dockerfile          # Multi-stage: development | production
โ”‚   โ”‚   โ”œโ”€โ”€ php.ini             # Dev config (debug on, opcache off)
โ”‚   โ”‚   โ”œโ”€โ”€ php-prod.ini        # Prod config (opcache + JIT)
โ”‚   โ”‚   โ”œโ”€โ”€ www.conf            # PHP-FPM pool
โ”‚   โ”‚   โ”œโ”€โ”€ xdebug.ini          # Xdebug 3 (dev only)
โ”‚   โ”‚   โ””โ”€โ”€ entrypoint.sh       # Prod: config:cache, route:cache...
โ”‚   โ”œโ”€โ”€ nginx/
โ”‚   โ”‚   โ”œโ”€โ”€ Dockerfile
โ”‚   โ”‚   โ””โ”€โ”€ conf.d/app.conf     # Gzip, security headers, PHP-FPM
โ”‚   โ”œโ”€โ”€ cron/Dockerfile         # Laravel Scheduler
โ”‚   โ”œโ”€โ”€ mysql/init/             # MySQL init scripts
โ”‚   โ””โ”€โ”€ pgsql/init/             # PostgreSQL init scripts
โ”œโ”€โ”€ .github/
โ”‚   โ”œโ”€โ”€ workflows/
โ”‚   โ”‚   โ”œโ”€โ”€ ci.yml              # Tests on PR (MySQL + PostgreSQL)
โ”‚   โ”‚   โ”œโ”€โ”€ deploy.yml          # Build GHCR image โ†’ SSH deploy
โ”‚   โ”‚   โ””โ”€โ”€ rollback.yml        # One-click rollback from GitHub UI
โ”‚   โ”œโ”€โ”€ ISSUE_TEMPLATE/         # Bug + Feature request templates
โ”‚   โ””โ”€โ”€ pull_request_template.md
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ deploy.sh               # Releases by git SHA, current symlink
โ”‚   โ””โ”€โ”€ rollback.sh             # Instant rollback to previous SHA
โ”œโ”€โ”€ docker-compose.yml          # Base services
โ”œโ”€โ”€ docker-compose.dev.yml      # + Xdebug, Mailpit, Vite
โ”œโ”€โ”€ docker-compose.staging.yml  # Prod images, resource limits
โ”œโ”€โ”€ docker-compose.prod.yml     # Prod images, strict limits, JSON logging
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ Makefile                    # Shortcuts for all operations

๐Ÿš€ Quick Start

Full step-by-step guide โ†’ QUICKSTART.md

New project (install Laravel inside Docker โ€” no local PHP required)

git clone https://github.com/serwin35/docker-laravel-starter.git my-project
cd my-project
cp .env.example .env

make laravel-new      # installs Laravel inside the container
make setup DB=mysql   # build + up + key:generate + migrate

Existing Laravel project

# Inside your existing Laravel project directory:
curl -fsSL https://github.com/serwin35/docker-laravel-starter/archive/refs/heads/main.tar.gz \
  | tar xz --strip-components=1 \
    --exclude='docker-laravel-starter-main/README.md' \
    --exclude='docker-laravel-starter-main/LICENSE' \
    --exclude='docker-laravel-starter-main/.git'

# Merge .env.example Docker variables into your existing .env
make up DB=mysql
make migrate

App available at http://localhost:80


๐Ÿ—„๏ธ Database Selection

Switch between MySQL and PostgreSQL via Docker profiles:

make up DB=mysql    # mysql:8.4
make up DB=pgsql    # postgres:16-alpine

Update .env accordingly:

# MySQL
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306

# PostgreSQL
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432

๐Ÿ› ๏ธ Makefile Reference

# First run
make laravel-new          # Install fresh Laravel inside the container (no local PHP)
make setup DB=mysql       # Build + up + install + key:generate + migrate

# Environment management
make up DB=mysql          # Start (DB=mysql|pgsql, ENV=dev|staging|prod)
make down                 # Stop all containers
make ps                   # Container status
make logs                 # Tail logs (ARGS=php to filter one service)
make shell                # bash inside the php container

# Laravel
make artisan  ARGS="make:model Post -mcr"
make composer ARGS="require spatie/laravel-permission"
make migrate
make seed
make fresh                # migrate:fresh --seed
make tinker
make cache-clear          # Clear all Laravel caches

# Testing
make test
make coverage
make lint                 # PHP Pint
make analyse              # PHPStan

# Frontend
make npm-dev              # Vite dev server with hot-reload
make npm-build            # Production asset build
make npm ARGS="add alpinejs"

# Database CLI
make db-mysql
make db-pgsql
make db-redis

# Optional services (require profiles)
COMPOSE_PROFILES=minio,mysql   make up   # + MinIO S3 storage
COMPOSE_PROFILES=reverb,mysql  make up   # + Laravel Reverb WebSocket
COMPOSE_PROFILES=npm,mysql     make up   # + Vite dev server in background

๐Ÿ”„ Zero-Downtime Releases & Rollback

One of the key features of this starter is the git SHA-based releases system โ€” the same pattern used by Deployer, Capistrano and Envoyer, implemented in pure Bash + Docker.

How it works

/var/www/myapp/
โ”œโ”€โ”€ releases/
โ”‚   โ”œโ”€โ”€ a1b2c3d4.../    โ† two weeks ago
โ”‚   โ”œโ”€โ”€ e5f6g7h8.../    โ† previous deploy   (available for rollback)
โ”‚   โ””โ”€โ”€ i9j0k1l2.../    โ† active deploy     โ† current points here
โ”‚
โ”œโ”€โ”€ shared/
โ”‚   โ”œโ”€โ”€ .env            โ† shared โ€” CI uploads before each deploy
โ”‚   โ””โ”€โ”€ storage/        โ† logs, uploads, cache โ€” persistent across releases
โ”‚
โ””โ”€โ”€ current -> releases/i9j0k1l2...    โ† symlink, switched atomically

Every deploy

  1. Creates releases/{git-sha}/ directory
  2. Extracts code via git archive
  3. Symlinks shared/.env and shared/storage/
  4. Switches current symlink atomically (mv -T) โ€” zero downtime
  5. Runs docker compose up -d --wait โ€” containers start with new code
  6. Runs php artisan migrate --force
  7. Prunes old releases (keeps last 5 by default)

Rollback โ€” one click

Via GitHub UI (recommended):

Actions โ†’ Rollback โ†’ select environment โ†’ Run workflow

Via SSH on the server:

# Roll back to the previous release automatically:
DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh

# Roll back to a specific commit:
GIT_SHA=e5f6g7h8 DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh

Rollback is instant โ€” it only switches the symlink and restarts containers. No image pull needed.

Each release directory is named after the git commit SHA, so you can always trace exactly what code is running: git show i9j0k1l2.


๐Ÿ” Environments

Development (default)

make up              # docker compose -f base -f dev

Includes: Xdebug, Mailpit (http://localhost:8025), Vite dev server, bind mounts.

Staging

make up ENV=staging DB=mysql

Production PHP image, resource limits (1 CPU / 512M RAM).

Production

make up ENV=prod DB=mysql

Production image, strict limits (2 CPU / 1G RAM), JSON logging, restart: always.


โš™๏ธ CI/CD Pipeline

CI (every Pull Request)

Pull Request โ†’ Lint (Pint) โ†’ PHPStan โ†’ Tests on MySQL โ†’ Tests on PostgreSQL

CD (push to branch)

develop โ†’ dev server
staging โ†’ staging server
main    โ†’ production server  (+ required reviewers)

Deploy Flow

1. npm run build               (frontend assets)
2. Build PHP image (prod)      (code + vendor baked in)
3. Build Nginx image (prod)    (public/ assets baked in)
4. Push both to GHCR
5. Dynamic .env built from GitHub Environment vars/secrets
6. SSH โ†’ run deploy.sh:
   - Create releases/{git-sha}/
   - Symlink shared/.env + shared/storage/
   - Switch current โ†’ new release (atomic)
   - docker compose up -d --wait
   - php artisan migrate --force
7. Smoke test: GET /up โ†’ 200 OK

Rollback

# Via GitHub UI (recommended):
Actions โ†’ Rollback โ†’ choose env โ†’ Run workflow

# Via SSH:
DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh

# To specific commit:
GIT_SHA=abc1234 DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh

๐Ÿ” GitHub Environments Setup

Create three environments: dev, staging, prod in Settings โ†’ Environments.

Required per environment:

Type Name Description
Secret SSH_HOST Server IP or hostname
Secret SSH_USER Deploy user
Secret SSH_KEY Private SSH key
Var SSH_PORT SSH port (default 22)
Var DEPLOY_PATH Absolute path on server
Var APP_URL For smoke test
Var DB_PROFILE mysql or pgsql
Secret APP_KEY Laravel app key
Secret DB_PASSWORD Database password

All other vars/secrets are automatically written to .env โ€” no manual enumeration needed.


๐Ÿ› Xdebug

Pre-configured for PhpStorm and VS Code on port 9003:

# .env
XDEBUG_MODE=debug       # step debugging
XDEBUG_MODE=coverage    # code coverage
XDEBUG_MODE=off         # disabled (faster)

๐Ÿค Contributing

Contributions are welcome! This project uses GitHub Actions โ€” your merged PR counts toward the Open Sourcerer achievement.

See CONTRIBUTING.md for guidelines.

Good first issues: github.com/serwin35/docker-laravel-starter/issues?q=label%3A%22good+first+issue%22


๐Ÿ’ฌ Discussions & Support

Have a question or idea? Use GitHub Discussions.


โญ Show Your Support

If this starter kit saves you time โ€” please star โญ the repo. It helps others discover the project and motivates continued development.


๐Ÿ“„ License

MIT โ€” free to use in commercial projects.


Made with โค๏ธ by @serwin35

About

Production-ready Laravel Docker Starter Kit โ€” PHP 8.4, Nginx, MySQL/PostgreSQL, Redis, CI/CD with releases & rollback

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Sponsor this project

Packages

Contributors

Languages

You are visitor 01402792 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.