Last active
October 27, 2026 12:54
-
-
Save devhammed/425f32c2a81dff86bfd36e6308308d2d to your computer and use it in GitHub Desktop.
Laravel Docker Setup (Caddy, FrankenPHP, Queue Worker, Octane, Scheduler, Reverb)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| {$CADDY_GLOBAL_OPTIONS} | |
| admin {$CADDY_SERVER_ADMIN_HOST:localhost}:{$CADDY_SERVER_ADMIN_PORT:2019} | |
| log { | |
| level {$CADDY_SERVER_LOG_LEVEL:INFO} | |
| output {$CADDY_SERVER_LOG_OUTPUT:stderr} | |
| # Redact the authorization parameters... | |
| format filter { | |
| wrap {$CADDY_SERVER_LOGGER:json} | |
| fields { | |
| request>headers>X-Xsrf-Token replace REDACTED | |
| request>query>authorization replace REDACTED | |
| } | |
| } | |
| } | |
| frankenphp { | |
| worker { | |
| file "{$APP_PUBLIC_PATH:/var/www/html/public}/frankenphp-worker.php" | |
| {$CADDY_SERVER_WORKER_DIRECTIVE} | |
| {$CADDY_SERVER_WATCH_DIRECTIVES} | |
| } | |
| } | |
| servers { | |
| # Trust Loopback + Docker + Cloudflare ranges | |
| trusted_proxies static private_ranges \ | |
| 10.0.0.0/8 \ | |
| 173.245.48.0/20 \ | |
| 103.21.244.0/22 \ | |
| 103.22.200.0/22 \ | |
| 103.31.4.0/22 \ | |
| 141.101.64.0/18 \ | |
| 108.162.192.0/18 \ | |
| 190.93.240.0/20 \ | |
| 188.114.96.0/20 \ | |
| 197.234.240.0/22 \ | |
| 198.41.128.0/17 \ | |
| 162.158.0.0/15 \ | |
| 104.16.0.0/13 \ | |
| 104.24.0.0/14 \ | |
| 172.64.0.0/13 \ | |
| 31.0.72.0/22 \ | |
| 2400:cb00::/32 \ | |
| 2606:4700::/32 \ | |
| 2803:f800::/32 \ | |
| 2405:b500::/32 \ | |
| 2405:8100::/32 \ | |
| 2a06:98c0::/29 \ | |
| 2c0f:f248::/32 | |
| # Walk the header right-to-left past trusted proxies instead of taking the first (client-supplied) entry | |
| trusted_proxies_strict | |
| # Prefer Cloudflare's header; keep XFF and XRI as fallback | |
| client_ip_headers CF-Connecting-IP X-Forwarded-For X-Real-IP | |
| } | |
| } | |
| {$CADDY_EXTRA_CONFIG} | |
| {$CADDY_SERVER_SERVER_NAME:http://127.0.0.1:8000} { | |
| log | |
| route { | |
| root * "{$APP_PUBLIC_PATH:/var/www/html/public}" | |
| encode zstd br gzip | |
| # Mercure configuration is injected here... | |
| {$CADDY_SERVER_EXTRA_DIRECTIVES} | |
| request_body { | |
| max_size 256MB | |
| } | |
| # Favicon/robots/sitemaps: skip noisy logs | |
| @meta path /favicon.ico /robots.txt /sitemap.xml | |
| log_skip @meta | |
| # Static assets (long cache) | |
| @static { | |
| path *.css *.css.map *.js *.js.map *.jpg *.jpeg *.png *.gif *.ico *.cur *.heic *.webp *.tif *.tiff *.mp3 *.m4a *.aac *.ogg *.midi *.mid *.wav *.mp4 *.mov *.webm *.mpeg *.mpg *.avi *.ogv *.flv *.wmv *.htc *.gz *.svg *.svgz *.ttf *.ttc *.otf *.eot *.woff *.woff2 | |
| } | |
| header @static Cache-Control "public, immutable, stale-while-revalidate, max-age=31536000" | |
| # Fonts/SVG: allow cross-origin usage (cache header inherited from @static) | |
| @fonts { | |
| path *.svg *.svgz *.ttf *.ttc *.otf *.eot *.woff *.woff2 | |
| } | |
| header @fonts Access-Control-Allow-Origin "*" | |
| # Short-lived static assets | |
| @static-short { | |
| path *.json *.xml *.rss | |
| } | |
| header @static-short Cache-Control "no-cache, max-age=3600" | |
| # Block access to PHP and other files that may expose sensitive information | |
| # Reference: Livewire arbitrary file upload (GHSA-29cq-5w36-x7w3) | |
| @rejected { | |
| path *.php *.php/* *.bak *.conf *.config *.dist *.inc *.ini *.log *.sh *.sql *.swp *.swo *~ */.* | |
| # EXCEPTION: /.well-known/* is allowed per RFC 8615 for ACME challenges | |
| # https://www.rfc-editor.org/rfc/rfc8615 | |
| not path /.well-known/* | |
| } | |
| respond @rejected 404 | |
| @php2shell expression `{header.Cookie}.matches("(?i)(?:p|%[57]0)(?:h|%[46]8)(?:p|%[57]0)(?:s|%[57]3)(?:e|%[46]5)(?:s|%[57]3)(?:s|%[57]3)(?:i|%[46]9)(?:d|%[46]4)") || {query}.matches("(?i)(?:p|%[57]0)(?:h|%[46]8)(?:p|%[57]0)(?:s|%[57]3)(?:e|%[46]5)(?:s|%[57]3)(?:s|%[57]3)(?:i|%[46]9)(?:d|%[46]4)") || {header.Content-Type}.matches("(?i)multipart/form-data")` | |
| respond @php2shell 404 | |
| # Security Headers | |
| # https://owasp.org/www-project-secure-headers/ | |
| header { | |
| defer | |
| # Prevent clickjacking attacks by disabling iframe embedding | |
| X-Frame-Options "SAMEORIGIN" | |
| # Prevent MIME type sniffing attacks | |
| X-Content-Type-Options "nosniff" | |
| # Control referrer information sent with requests | |
| Referrer-Policy "strict-origin-when-cross-origin" | |
| # Enable strict transport security (HSTS) | |
| Strict-Transport-Security "max-age=31536000; includeSubDomains" | |
| # Remove server identification headers | |
| -Server | |
| -X-Powered-By | |
| } | |
| @reverb path "{$REVERB_SERVER_PATH}/app/*" "{$REVERB_SERVER_PATH}/apps/*" | |
| reverse_proxy @reverb {$REVERB_SERVER_HOST:0.0.0.0}:{$REVERB_SERVER_PORT:8080} | |
| php_server { | |
| index frankenphp-worker.php | |
| try_files {path} frankenphp-worker.php | |
| # FrankenPHP sets REMOTE_ADDR from the TCP peer, which ignores trusted_proxies | |
| env REMOTE_ADDR {client_ip} | |
| # Required for the public/storage/ directory... | |
| resolve_root_symlink | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setup base image | |
| FROM dunglas/frankenphp:1-php8.5-bookworm | |
| # Setup application root | |
| WORKDIR /var/www/html | |
| # Copy application source | |
| COPY . . | |
| # Install dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| git \ | |
| zip \ | |
| unzip \ | |
| libpq-dev \ | |
| libpng-dev \ | |
| libonig-dev \ | |
| libxml2-dev \ | |
| libicu-dev \ | |
| libuv1-dev \ | |
| curl \ | |
| supervisor \ | |
| ffmpeg \ | |
| && install-php-extensions pdo_pgsql mbstring bcmath pcntl gd exif intl redis \ | |
| && pecl install uv-beta \ | |
| && docker-php-ext-enable uv \ | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ | |
| && composer install --prefer-dist --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader --ignore-platform-reqs \ | |
| && composer clear-cache \ | |
| && composer dump-autoload --optimize \ | |
| && php artisan storage:link \ | |
| && curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \ | |
| && apt-get install -y nodejs \ | |
| && npm install -g npm \ | |
| && npm ci \ | |
| && chown -R www-data:www-data /var/www/html \ | |
| && cp .docker/Caddyfile /etc/caddy/Caddyfile \ | |
| && cp .docker/php.ini /usr/local/etc/php/conf.d/user-php.ini \ | |
| && cp .docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf \ | |
| && cp .docker/run.sh /usr/local/bin/run.sh \ | |
| && chmod +x /usr/local/bin/run.sh | |
| # Switch user | |
| USER www-data | |
| # Expose FrankenPHP | |
| EXPOSE 8000 | |
| # Start container | |
| ENTRYPOINT ["/usr/local/bin/run.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| upload_max_filesize = 128M | |
| post_max_size = 256M | |
| memory_limit = 512M | |
| max_execution_time = 300 | |
| opcache.enable = 1 | |
| opcache.enable_cli = 1 | |
| opcache.memory_consumption = 256 | |
| opcache.interned_strings_buffer = 32 | |
| opcache.max_accelerated_files = 100000 | |
| opcache.validate_timestamps = 1 | |
| opcache.revalidate_freq = 2 | |
| opcache.save_comments = 1 | |
| opcache.jit = 0 | |
| opcache.jit_buffer_size = 0 | |
| opcache.enable_file_override = 0 | |
| session.upload_progress.enabled = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Exit on error | |
| set -eux | |
| # Run database migrations | |
| php artisan migrate --force --seed | |
| # Clear Laravel caches | |
| php artisan optimize:clear | |
| # Rebuild Laravel caches | |
| php artisan optimize | |
| # Build frontend assets | |
| npm run build | |
| # Start supervisor | |
| exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [supervisord] | |
| user=www-data | |
| nodaemon=true | |
| minfds=50000 | |
| [program:frankenphp] | |
| command=php artisan octane:frankenphp --caddyfile /etc/caddy/Caddyfile --log-level INFO | |
| directory=/var/www/html | |
| autostart=true | |
| autorestart=true | |
| priority=5 | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 | |
| [program:queue-worker] | |
| command=php artisan queue:work --sleep=3 --tries=3 --max-time=3600 | |
| process_name=%(program_name)s_%(process_num)02d | |
| numprocs=10 | |
| directory=/var/www/html | |
| autostart=true | |
| autorestart=true | |
| stopasgroup=true | |
| killasgroup=true | |
| stopwaitsecs=3600 | |
| priority=10 | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 | |
| [program:scheduler] | |
| command=php artisan schedule:work --run-output-file=/dev/stdout | |
| directory=/var/www/html | |
| autostart=true | |
| autorestart=true | |
| priority=10 | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 | |
| [program:reverb] | |
| command=php artisan reverb:start --host=127.0.0.1 --port=8080 | |
| directory=/var/www/html | |
| autostart=true | |
| autorestart=true | |
| priority=10 | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment