Compare commits

..

1 Commits

Author SHA1 Message Date
Fabian @ Blax Software 96bca57bde fix(perms,mysql): auto-fix storage ownership + skip self-signed cert verify
Two recurring foot-guns in production stacks rolled into one image-level fix:

1. storage/ + bootstrap/cache/ ownership drift. ENABLE_LARAVEL_PERMS was
   opt-in (default 0) and only chmod'd the top-level dir — so any subdir
   created later by a different UID (root, nobody, …) stayed un-writable
   for www-data. Symptom: workkit:db:backup pumping a multi-GB mysqldump
   into a doomed bash redirect that fails with "Permission denied" only
   after the pipeline starts. Now default-on (=1), recursive chown +
   chmod ug+rwX, SGID on dirs so future files inherit the group, and we
   pre-create the subdirs that ship empty (incl. storage/backups/) so
   artisan never creates one as the wrong user.

2. mysql client TLS verification against self-signed in-cluster certs.
   `php artisan db` failed with "TLS/SSL error: self-signed certificate
   in certificate chain" because modern mysql/mariadb clients auto-enable
   ssl-verify-server-cert when a password is on argv. Drops a
   /etc/mysql/conf.d/00-laravel-client.cnf with ssl-verify-server-cert=OFF
   so the connection still negotiates TLS but skips the chain check —
   the right tradeoff for a private docker network. Override per-host
   with MYSQL_CLIENT_VERIFY=ON or by mounting a stricter .cnf.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 10:05:14 +02:00
10 changed files with 21 additions and 186 deletions

View File

@ -2,7 +2,7 @@
# docker-laravel — Multi-version PHP + Nginx image for Laravel
#
# Build args:
# PHP_VERSION — 7.4 | 8.0 | 8.1 | 8.2 | 8.3 | 8.4 | 8.5 | 8.6 (default: 8.4)
# PHP_VERSION — 7.4 | 8.0 | 8.1 | 8.2 | 8.3 | 8.4 | 8.5 (default: 8.4)
# NODE_MAJOR — Node.js major version (default: 22)
# ===========================================================================
ARG PHP_VERSION=8.4
@ -26,7 +26,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# ---------------------------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
gnupg gosu curl wget ca-certificates zip unzip git \
supervisor tini sqlite3 libcap2-bin python3 pkg-config \
supervisor sqlite3 libcap2-bin python3 pkg-config \
# GD
libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev \
# PHP extension libs
@ -35,8 +35,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
# ImageMagick
libmagickwand-dev \
# librsvg: crisp SVG->PDF/PNG (rsvg-convert) + Imagick's preferred SVG delegate
librsvg2-bin librsvg2-2 \
# Nginx + headers-more module
nginx libnginx-mod-http-headers-more-filter \
# Database clients
@ -48,15 +46,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# ---------------------------------------------------------------------------
# PHP extensions
# ---------------------------------------------------------------------------
# GD configure flags changed between PHP 7.x and 8.0. Since PHP 8.5 OPcache is built
# into PHP itself (already loaded in php:8.5-fpm and later), so it is only built before.
# GD configure flags changed between PHP 7.x and 8.0
RUN PHP_MAJOR=$(php -r "echo PHP_MAJOR_VERSION;") && \
if [ "$PHP_MAJOR" -ge 8 ]; then \
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \
else \
docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-webp-dir=/usr; \
fi && \
OPCACHE_EXT=$(php -m | grep -q '^Zend OPcache$' || echo opcache) && \
docker-php-ext-install -j$(nproc) \
pdo_mysql \
pdo_pgsql \
@ -71,14 +67,13 @@ RUN PHP_MAJOR=$(php -r "echo PHP_MAJOR_VERSION;") && \
xml \
soap \
intl \
$OPCACHE_EXT
opcache
# PECL extensions (fail gracefully for bleeding-edge PHP; see scripts/pecl-install)
COPY scripts/pecl-install /usr/local/bin/pecl-install
RUN pecl-install redis || echo "NOTICE: redis unavailable for PHP ${PHP_VERSION}"
RUN pecl-install ev || echo "NOTICE: ev unavailable for PHP ${PHP_VERSION}"
RUN pecl-install igbinary || echo "NOTICE: igbinary unavailable for PHP ${PHP_VERSION}"
RUN pecl-install imagick || echo "NOTICE: imagick unavailable for PHP ${PHP_VERSION}"
# PECL extensions (fail gracefully for bleeding-edge PHP)
RUN pecl install redis && docker-php-ext-enable redis || echo "NOTICE: redis unavailable for PHP ${PHP_VERSION}"
RUN pecl install ev && docker-php-ext-enable ev || echo "NOTICE: ev unavailable for PHP ${PHP_VERSION}"
RUN pecl install igbinary && docker-php-ext-enable igbinary || echo "NOTICE: igbinary unavailable for PHP ${PHP_VERSION}"
RUN pecl install imagick && docker-php-ext-enable imagick || echo "NOTICE: imagick unavailable for PHP ${PHP_VERSION}"
# ---------------------------------------------------------------------------
# OPcache configuration (JIT enabled automatically for PHP 8.0+)
@ -159,11 +154,10 @@ RUN mkdir -p /etc/supervisor/conf.d /etc/supervisor/laravel.d /etc/supervisor/cu
/var/log/supervisor /var/log/nginx /var/log/php
# ---------------------------------------------------------------------------
# Startup script + healthcheck
# Startup script
# ---------------------------------------------------------------------------
COPY scripts/start-container /usr/local/bin/start-container
COPY scripts/container-health /usr/local/bin/container-health
RUN chmod +x /usr/local/bin/start-container /usr/local/bin/container-health
RUN chmod +x /usr/local/bin/start-container
# Composer cache
RUN mkdir -p /.composer && chmod 0777 /.composer
@ -185,24 +179,5 @@ ENV MYSQL_CLIENT_VERIFY=OFF
EXPOSE 80
# Report UNHEALTHY when an expected supervised process (php-fpm, nginx, or any
# enabled queue/scheduler/horizon worker) is not RUNNING — so a dead worker
# surfaces in `docker ps`/orchestration instead of silently dropping jobs.
# start-period gives supervisord + a slow DB time to come up before counting.
HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
CMD container-health
# Boot supervisord (php-fpm + nginx + enabled workers) via start-container. This
# MUST stay — without it the base php image's default entrypoint runs php-fpm
# alone (no nginx -> port 80 unserved, no supervisord -> healthcheck fails).
#
# tini is PID 1 (not supervisord directly) purely as a defense-in-depth zombie
# reaper: any process reparented to PID 1 — e.g. a child orphaned by a program
# that forks and exits without waiting (the laravel-websockets fork-per-message
# server on restart) — is reaped by tini. supervisord already reaps its own
# tree and reparented orphans, so this is belt-and-suspenders that mirrors the
# docker-bastion image. No `-g`: tini forwards SIGTERM to its direct child
# (supervisord), preserving supervisord's ordered, per-program graceful stop
# (queue stopwaitsecs, etc.). No `-s`: tini is already PID 1.
ENTRYPOINT ["/usr/bin/tini", "--", "start-container"]
ENTRYPOINT ["start-container"]

View File

@ -6,7 +6,7 @@ A **runtime environment** for Laravel applications — not Laravel itself.
This image provides everything a Laravel app needs to run: PHP-FPM, Nginx, Composer, Node.js, and a curated set of PHP extensions and system tools. Mount your Laravel project at `/var/www/html` and you're ready to go.
Built for PHP 7.4 through 8.6, covering Laravel 9 – 13.
Built for PHP 7.4 through 8.5, covering Laravel 9 – 13.
## Available Tags
@ -21,7 +21,6 @@ Built for PHP 7.4 through 8.6, covering Laravel 9 – 13.
| `blaxsoftware/laravel:php8.3` | 8.3 | 10, 11, 12, 13 |
| `blaxsoftware/laravel:php8.4` | 8.4 | 11, 12, 13 |
| `blaxsoftware/laravel:php8.5` | 8.5 | 12, 13 |
| `blaxsoftware/laravel:php8.6` | 8.6 | 13 |
| `blaxsoftware/laravel:latest` | 8.4 | (alias for php8.4) |
### By Laravel version (recommended PHP)
@ -53,7 +52,6 @@ blaxsoftware/laravel:laravel12-php8.5
blaxsoftware/laravel:laravel13-php8.3
blaxsoftware/laravel:laravel13-php8.4
blaxsoftware/laravel:laravel13-php8.5
blaxsoftware/laravel:laravel13-php8.6
```
## Quick Start
@ -75,19 +73,6 @@ docker buildx bake
docker buildx bake active
```
### Before you push a rebuilt image
The base tag `php:<version>-fpm` isn't pinned, and a PECL extension that fails to
build only prints a `NOTICE` (Dockerfile, the `pecl install … || echo` lines). So a
rebuild can succeed without redis or imagick, and every app on that tag breaks at
its next restart. Before `docker push`, count the PECL extensions in the new image
and compare with the image it replaces:
```bash
docker run --rm --entrypoint php blaxsoftware/laravel:laravel11 -m | grep -cE '^(redis|ev|igbinary|imagick)$'
# 4 on PHP 8.4. A newer PHP may lack one by design; the count must never be lower than the previous image of the same tag.
```
## plug-n-pray 🙏
Generate a full Docker Compose boilerplate for any Laravel project:
@ -143,10 +128,9 @@ services:
## What's Included
- **PHP-FPM** with extensions: pdo_mysql, pdo_pgsql, mysqli, mbstring, exif, pcntl, bcmath, gd (freetype + jpeg + webp), sockets, zip, xml, soap, intl, opcache
- **PECL**: redis, ev, igbinary, imagick (graceful fallback if unavailable for a PHP version). PHP 8.6 images ship without `pecl`, so `scripts/pecl-install` builds the newest pecl.php.net release from source. On 2026-11-20 (PHP 8.6.0, one day old) only `ev` compiles; redis, igbinary and imagick still use C APIs 8.6 removed. Apps on `php8.6` use predis until a rebuild picks up phpredis.
- **PECL**: redis, ev, igbinary, imagick (graceful fallback if unavailable for a PHP version)
- **OPcache** with JIT auto-enabled on PHP 8.0+
- **Nginx** with headers-more module, optimized for Laravel
- **X-Accel-Redirect** for files under `storage/app`: after its own access check the app answers with an empty body and `X-Accel-Redirect: /_accel/<path under storage/app>`, and nginx sends the file (Range requests, CORS headers passed on). The internal location is announced to PHP as `$_SERVER['X_ACCEL_STORAGE'] = '/_accel/'`, so an app can switch it on only when the image has it
- **Composer** (latest)
- **Node.js** + npm
- **Image optimizers**: optipng, pngquant, gifsicle, webp, avif, svgo
@ -201,10 +185,6 @@ command=/usr/sbin/nginx -g "daemon off;"
autostart=false
```
## Maintainer
Maintained by [Blax Software](https://www.blax.at/digital/hosting), a software practice in Austria. Bugs and pull requests go to this repository; for project work, write to office@blax.at.
## Star History
<a href="https://www.star-history.com/?repos=blax-software%2Fdocker-laravel&type=date&legend=top-left">

View File

@ -21,22 +21,6 @@ server {
try_files $uri $uri/ /index.php?$query_string;
}
# Files Laravel has authorised (X-Accel-Redirect): PHP checks access, then
# answers with an empty body and "X-Accel-Redirect: /_accel/<path under
# storage/app>", and nginx sends the file itself, Range requests included.
# internal: no client can request it directly. On this redirect nginx keeps
# only a few upstream headers (Content-Type, Cache-Control, Expires,
# Content-Disposition, Set-Cookie, Accept-Ranges), so the CORS ones are
# passed on here; an empty value adds no header.
location ^~ /_accel/ {
internal;
alias /var/www/html/storage/app/;
add_header Access-Control-Allow-Origin $upstream_http_access_control_allow_origin always;
add_header Access-Control-Allow-Credentials $upstream_http_access_control_allow_credentials always;
add_header Access-Control-Expose-Headers $upstream_http_access_control_expose_headers always;
add_header Vary $upstream_http_vary always;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param HTTP_PROXY "";
@ -45,10 +29,6 @@ server {
fastcgi_param SERVER_NAME $host;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
# Tells the app that /_accel/ exists (above). A server variable, not a
# request header, so a client cannot fake it; without it the app streams
# files through PHP as before.
fastcgi_param X_ACCEL_STORAGE /_accel/;
include fastcgi_params;
}
}

View File

@ -5,9 +5,6 @@ memory_limit = 500M
variables_order = EGPCS
fastcgi.logging = Off
; Laravel never reads upload progress; off by default since PHP2Shell (CVE-2026-109618)
session.upload_progress.enabled = Off
; Error Reporting
display_errors = Off
log_errors = On

View File

@ -106,26 +106,16 @@ target "php-85" {
tags = [tag("8.5")]
}
target "php-86" {
context = "."
dockerfile = "Dockerfile"
args = {
PHP_VERSION = "8.6"
NODE_MAJOR = "${NODE_MAJOR}"
}
tags = [tag("8.6")]
}
# ---------------------------------------------------------------------------
# Groups
# ---------------------------------------------------------------------------
group "default" {
targets = ["php-74", "php-80", "php-81", "php-82", "php-83", "php-84", "php-85", "php-86"]
targets = ["php-74", "php-80", "php-81", "php-82", "php-83", "php-84", "php-85"]
}
group "active" {
targets = ["php-82", "php-83", "php-84", "php-85", "php-86"]
targets = ["php-82", "php-83", "php-84", "php-85"]
}
group "legacy" {

View File

@ -28,7 +28,6 @@ declare -A PHP_LARAVEL_MAP=(
["8.3"]="10 11 12 13"
["8.4"]="11 12 13"
["8.5"]="12 13"
["8.6"]="13"
)
# Recommended (highest) PHP version per Laravel version → gets the bare `laravelN` tag
@ -43,7 +42,7 @@ declare -A LARAVEL_RECOMMENDED_PHP=(
# Which PHP version gets the `latest` tag
LATEST_PHP="8.4"
ALL_PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4" "8.5" "8.6")
ALL_PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4" "8.5")
# ---------------------------------------------------------------------------
# Determine which versions to build

View File

@ -1,40 +0,0 @@
#!/usr/bin/env bash
# ===========================================================================
# container-health — Docker HEALTHCHECK for the docker-laravel image.
#
# Asserts that every supervisor program that is SUPPOSED to be running (the
# core web stack, plus whichever ENABLE_* services are on) is actually in the
# RUNNING state. If a queue worker or scheduler has crashed and supervisor gave
# up (FATAL), or never started, the container is reported UNHEALTHY — so a dead
# worker is visible in `docker ps` / orchestration instead of silently letting
# jobs pile up.
#
# Exit 0 = healthy, 1 = unhealthy. Used by HEALTHCHECK in the Dockerfile.
# ===========================================================================
set -uo pipefail
# Programs that must always be up.
expected=(php-fpm nginx)
# Optional services, gated by the same env vars start-container reads.
[ "${ENABLE_QUEUE:-false}" = "true" ] && expected+=(queue)
[ "${ENABLE_SCHEDULER:-false}" = "true" ] && expected+=(scheduler)
[ "${ENABLE_HORIZON:-false}" = "true" ] && expected+=(horizon)
status="$(supervisorctl status 2>/dev/null)"
if [ -z "$status" ]; then
echo "UNHEALTHY: supervisorctl returned no status (supervisord down?)"
exit 1
fi
rc=0
for p in "${expected[@]}"; do
# supervisorctl prints e.g. "queue RUNNING pid 123, uptime 0:10:00"
if ! echo "$status" | grep -qE "^${p}([:_][^ ]*)?[[:space:]]+RUNNING"; then
line="$(echo "$status" | grep -E "^${p}([:_][^ ]*)?[[:space:]]" || echo "${p} (missing)")"
echo "UNHEALTHY: '${p}' is not RUNNING -> ${line}"
rc=1
fi
done
exit $rc

View File

@ -1,15 +0,0 @@
#!/bin/sh
# pecl-install <extension>: build, install and enable a PECL extension.
# Uses `pecl` where the PHP image ships it. PHP 8.6+ images no longer include PEAR/pecl,
# so there it builds the newest release from the pecl.php.net source tarball instead.
set -e
ext="$1"
if command -v pecl >/dev/null 2>&1; then
pecl install "$ext"
else
dir="$(mktemp -d)"
curl -fsSL "https://pecl.php.net/get/$ext" | tar xz -C "$dir" --strip-components=1
(cd "$dir" && phpize && ./configure && make -j"$(nproc)" && make install)
rm -rf "$dir"
fi
docker-php-ext-enable "$ext"

View File

@ -39,7 +39,6 @@ declare -A PHP_LARAVEL_MAP=(
["8.3"]="10 11 12 13"
["8.4"]="11 12 13"
["8.5"]="12 13"
["8.6"]="13"
)
declare -A LARAVEL_RECOMMENDED_PHP=(
@ -51,7 +50,7 @@ declare -A LARAVEL_RECOMMENDED_PHP=(
)
LATEST_PHP="8.4"
ALL_PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4" "8.5" "8.6")
ALL_PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4" "8.5")
# ---------------------------------------------------------------------------
# Determine which versions to push

View File

@ -118,19 +118,9 @@ if [ "${ENABLE_QUEUE:-false}" = "true" ]; then
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan queue:work --tries=3 --sleep=5 --timeout=600 --max-jobs=500 --max-time=3600
autostart=true
autorestart=true
; A few rapid boot failures (e.g. DB not ready yet) must NOT make supervisor
; give up and mark the worker FATAL forever — that's how a queue silently dies
; and jobs pile up. Keep retrying generously; once it stays up past startsecs
; the counter resets, so the hourly --max-time exit never trips it.
startretries=30
startsecs=5
; Graceful shutdown on deploy/restart: queue:work handles SIGTERM by finishing
; the current job then exiting. Wait longer than --timeout before SIGKILL so an
; in-flight job is never killed mid-write (which would fail + retry it).
stopsignal=TERM
stopwaitsecs=630
user=www-data
priority=20
startsecs=5
stdout_logfile=/proc/1/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/proc/1/fd/2
@ -145,12 +135,9 @@ if [ "${ENABLE_SCHEDULER:-false}" = "true" ]; then
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan schedule:work
autostart=true
autorestart=true
startretries=30
startsecs=5
stopsignal=TERM
stopwaitsecs=60
user=www-data
priority=20
startsecs=5
stdout_logfile=/proc/1/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/proc/1/fd/2
@ -165,13 +152,9 @@ if [ "${ENABLE_HORIZON:-false}" = "true" ]; then
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan horizon
autostart=true
autorestart=true
startretries=30
startsecs=5
; Horizon traps SIGTERM and shuts its workers down gracefully.
stopsignal=TERM
stopwaitsecs=630
user=www-data
priority=20
startsecs=5
stdout_logfile=/proc/1/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/proc/1/fd/2
@ -179,19 +162,6 @@ stderr_logfile_maxbytes=0
CONF
fi
# Loud warning for the silent-failure mode this whole section exists to prevent:
# a database/redis queue with NO worker (or NO scheduler) means jobs/scheduled
# tasks accumulate forever with nothing processing them — exactly how a paid
# purchase can leave a user un-granted. `sync` is the one connection that runs
# jobs inline, so it's the only safe one without a worker.
QC="${QUEUE_CONNECTION:-sync}"
if [ "${ENABLE_QUEUE:-false}" != "true" ] && [ "${ENABLE_HORIZON:-false}" != "true" ] && [ "$QC" != "sync" ] && [ "$QC" != "null" ]; then
echo " !! WARNING: ENABLE_QUEUE=false but QUEUE_CONNECTION='${QC}' — queued jobs will PILE UP unprocessed (no worker). Set ENABLE_QUEUE=true, or QUEUE_CONNECTION=sync."
fi
if [ "${ENABLE_SCHEDULER:-false}" != "true" ]; then
echo " !! WARNING: ENABLE_SCHEDULER=false — scheduled tasks (cleanups, health checks, reminders) will NOT run."
fi
# Report custom programs
CUSTOM_COUNT=$(find /etc/supervisor/custom.d/ -name '*.conf' 2>/dev/null | wc -l)
if [ "$CUSTOM_COUNT" -gt 0 ]; then