docker-laravel/README.md

217 lines
10 KiB
Markdown
Raw Normal View History

[![Blax Software OSS](https://raw.githubusercontent.com/blax-software/laravel-workkit/master/art/oss-initiative-banner.svg)](https://github.com/blax-software)
# docker-laravel
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.
## Available Tags
### By PHP version
| Tag | PHP | Suitable for Laravel |
|-------------------------------|-----|----------------------|
| `blaxsoftware/laravel:php7.4` | 7.4 | Legacy (< 9) |
| `blaxsoftware/laravel:php8.0` | 8.0 | 9 |
| `blaxsoftware/laravel:php8.1` | 8.1 | 9, 10 |
| `blaxsoftware/laravel:php8.2` | 8.2 | 9, 10, 11, 12 |
| `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)
| Tag | Points to |
|----------------------------------|-----------|
| `blaxsoftware/laravel:laravel9` | php8.1 |
| `blaxsoftware/laravel:laravel10` | php8.3 |
| `blaxsoftware/laravel:laravel11` | php8.4 |
| `blaxsoftware/laravel:laravel12` | php8.5 |
| `blaxsoftware/laravel:laravel13` | php8.5 |
### Combo tags (specific PHP + Laravel)
```
blaxsoftware/laravel:laravel9-php8.0
blaxsoftware/laravel:laravel9-php8.1
blaxsoftware/laravel:laravel9-php8.2
blaxsoftware/laravel:laravel10-php8.1
blaxsoftware/laravel:laravel10-php8.2
blaxsoftware/laravel:laravel10-php8.3
blaxsoftware/laravel:laravel11-php8.2
blaxsoftware/laravel:laravel11-php8.3
blaxsoftware/laravel:laravel11-php8.4
blaxsoftware/laravel:laravel12-php8.2
blaxsoftware/laravel:laravel12-php8.3
blaxsoftware/laravel:laravel12-php8.4
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
```bash
# Build a single version
docker build --build-arg PHP_VERSION=8.4 -t docker-laravel:php8.4 .
# Build all versions
./scripts/build.sh
# Build only specific PHP versions
./scripts/build.sh 8.4 8.5
# Build all versions with buildx bake
docker buildx bake
# Build only actively-supported PHP versions
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:
```bash
# From your Laravel project root — one-liner:
curl -fsSL https://raw.githubusercontent.com/blax-software/docker-laravel/main/scripts/plug-n-pray.sh | bash
# With options:
./plug-n-pray.sh --php=8.4 --name=my-app --host=my-app.localhost --horizon
# Or via artisan (requires blax-software/laravel-workkit):
php artisan workkit:plug-n-pray
php artisan workkit:plug-n-pray --php=8.5 --horizon --no-mysql
```
See [docs/examples.md](docs/examples.md) for full usage examples.
## Usage in docker-compose.yml
```yaml
services:
app:
image: docker-laravel:php8.4
volumes:
- ./:/var/www/html
ports:
- "80:80"
environment:
ENABLE_QUEUE: "true"
ENABLE_SCHEDULER: "true"
ENABLE_HORIZON: "false"
ENABLE_LARAVEL_PERMS: "1"
```
## Build Args
| Arg | Default | Description |
|---------------|---------|------------------------------|
| `PHP_VERSION` | `8.4` | PHP version (7.4, 8.0 – 8.5) |
| `NODE_MAJOR` | `22` | Node.js major version |
## Runtime Environment Variables
| Variable | Default | Description |
|------------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ENABLE_QUEUE` | `false` | Start `artisan queue:work` via supervisor |
| `ENABLE_SCHEDULER` | `false` | Start `artisan schedule:work` via supervisor |
| `ENABLE_HORIZON` | `false` | Start `artisan horizon` via supervisor |
| `ENABLE_LARAVEL_PERMS` | `1` | Pre-create + chown -R www-data + chmod ug+rwX (with SGID) on `storage/` and `bootstrap/cache/` on every boot. Idempotent. Set to `0` to opt out. |
| `MYSQL_CLIENT_VERIFY` | `OFF` | Whether the bundled mysql/mariadb client verifies the server cert chain. Default `OFF` is right for in-cluster MySQL with a self-signed cert (the connection is still encrypted). Set to `ON` if you connect to a real public host. |
## 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.
- **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
- **ffmpeg**, **ghostscript**, **MySQL client**
## Architecture
```
start-container (entrypoint)
└─ supervisord
├─ php-fpm (always)
├─ nginx (always)
├─ queue.conf (if ENABLE_QUEUE=true)
├─ scheduler.conf (if ENABLE_SCHEDULER=true)
└─ horizon.conf (if ENABLE_HORIZON=true)
```
Optional supervisor configs are generated at runtime in `/etc/supervisor/laravel.d/`.
## Customizing Supervisor Programs
Every supervisor program lives in its own `.conf` file across three include directories:
| Directory | Purpose | How to customize |
|------------------------------|---------------------------------------------------------------------|--------------------------------------------------|
| `/etc/supervisor/conf.d/` | Core services (php-fpm, nginx) | Mount a replacement file to override |
| `/etc/supervisor/laravel.d/` | Queue, scheduler, horizon (auto-generated from `ENABLE_*` env vars) | Use env vars, or disable them and mount your own |
| `/etc/supervisor/custom.d/` | Empty — for your own programs | Mount a directory or individual files |
**Examples:**
```yaml
services:
app:
image: blaxsoftware/laravel:php8.4
volumes:
- ./:/var/www/html
# Override php-fpm config (e.g. change pool settings)
- ./docker/php-fpm.conf:/etc/supervisor/conf.d/php-fpm.conf
# Add custom programs (e.g. reverb, octane, custom workers)
- ./docker/supervisor/:/etc/supervisor/custom.d/
environment:
ENABLE_QUEUE: "true"
```
To **disable a core service** (e.g. nginx), mount an override with `autostart=false`:
```ini
; my-nginx-override.conf
[program:nginx]
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">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=blax-software/docker-laravel&type=date&theme=dark&legend=top-left" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=blax-software/docker-laravel&type=date&legend=top-left" />
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=blax-software/docker-laravel&type=date&legend=top-left" />
</picture>
</a>