How to Configure PHP‑FPM for Laravel is the single most consequential decision you'll make when moving a Laravel app from php artisan serve into something resembling a real production stack. PHP‑FPM is the FastCGI Process Manager that handles worker pools, request queuing, and graceful reloads far more gracefully than Apache's mod_php ever did, and in 2026 it remains the default workhorse beneath most serious Laravel deployments. This guide walks you through the exact configuration, Docker, and Traefik wiring that senior engineers actually use, with the tradeoffs spelled out instead of hand‑waved.
Quick Answer: What is PHP‑FPM and Why Laravel Needs It
PHP‑FPM (FastCGI Process Manager) is a separate process manager that talks to a web server over a FastCGI protocol, typically on port 9000 or a Unix socket. Instead of embedding PHP inside the web server, the web server forwards requests to PHP‑FPM workers, which compile and execute Laravel once per request and return the rendered response.
What is PHP‑FPM?
Definition: PHP‑FPM is the FastCGI Process Manager for PHP. It manages a pool of worker processes that handle incoming web requests, exposing each pool through a TCP port (default 9000) or a Unix socket for reverse proxies like Nginx, Traefik, or Caddy to forward to.
For Laravel, this matters because the framework boots a service container, registers service providers, and loads the configuration on every request when running under classic CGI. PHP‑FPM lets you control how many of those boots happen in parallel and how aggressively the OS should recycle them, which directly shapes throughput and tail latency.
Laravel's Default Server Options
Laravel ships with three built‑in ways to serve HTTP:
php artisan serve: a single‑process PHP development server, only suitable for local work.php artisan octane:start: long‑lived workers via Swoole, RoadRunner, or FrankenPHP, described in the production‑ready Laravel + Traefik guide on HackerNoon.- PHP‑FPM behind a reverse proxy: the canonical, low‑ops choice for the vast majority of teams.
When to Use PHP‑FPM in Development
Many tutorials treat PHP‑FPM as a production‑only concern, but running it locally gives you accurate performance metrics and eliminates mod_php overhead. If your staging and production boxes use PHP‑FPM, your CPU profile, opcache behavior, and request timing in development will be far more representative of real traffic.
PHP‑FPM Trends & Laravel Performance in 2026
PHP‑FPM is older than most of the frameworks it serves, but the way teams deploy it has changed considerably. The current stack looks more like a small platform than a single server.
Modern PHP Stack Evolution
By 2026, the dominant Laravel production pattern is one container per process: a PHP‑FPM container for web traffic, a Horizon container for queues, a Scheduler container for cron, a Redis container for cache and sessions, and a reverse proxy container for TLS and HTTP/2. The HackerNoon production guide documents this exact split, and it is what most CI/CD templates now generate by default.
Docker + PHP‑FPM + Traefik for Faster TTFB
Time to First Byte (TTFB) is dominated by framework boot, autoloader resolution, and config caching. A well‑sized PHP‑FPM pool with OPcache enabled routinely hits sub‑50ms TTFB on Laravel 11, even in modestly sized containers. The combination of Docker for isolation, PHP‑FPM for process management, and Traefik for TLS and HTTP/2 removes the connection‑level overhead that drags down naive Apache configurations.
Security & Debugging in Production
The biggest risk in 2026 isn't a zero‑day; it is a debug tool left enabled. Xdebug in production can leak stack traces, file paths, and environment variables in error responses. Treat any debugging extension as a build‑time decision, not a runtime toggle.
What You Need Before You Start
Before you start configuring, get the foundation right. Skipping this step is the single most common reason a "works on my machine" stack falls apart in staging.
Supported PHP Versions & Laravel Compatibility
Laravel 11 and 12 require PHP 8.2 or newer. In practice, that means running on the php:8.4-fpm base image, which is current as of 2026 and receives active security backports. Older 8.0/8.1 images are no longer supported upstream and should be considered legacy.
Docker, Docker‑Compose, Traefik, Xdebug, and Composer
You will need:
- Docker Engine and the Compose plugin (Docker Desktop is fine on macOS and Windows).
- Traefik v3.x if you want automated Let's Encrypt and HTTP/3.
- Xdebug 3.4.x for development debugging, installed via PECL.
- Composer 2.x for dependency management.
For Windows and macOS users, the Laravel News guide on Xdebug + Docker + PHP 8.4 is the cleanest reference for wiring up host.docker.internal so the IDE can reach the container.
Hardware & OS Considerations
For a single‑node development setup, 4 vCPUs and 8 GB of RAM is comfortable. In production, scale PHP‑FPM horizontally rather than vertically: keep each container's memory under 512 MB and run 4–8 of them behind Traefik. Snyk's guide on dockerizing PHP applications has solid baseline recommendations for image size and layer caching that apply here.
Step‑by‑Step Dockerfile & docker‑compose.yml
Below is the exact shape of a production‑grade setup. The key is the multi‑stage build that strips Xdebug out of the final image.
Creating the Dockerfile with php:8.4-fpm
# syntax=docker/dockerfile:1
FROM php:8.4-fpm AS base
# System deps for Laravel + OPcache + common PHP extensions
RUN apt-get update && apt-get install -y --no-install-recommends \
git unzip libicu-dev libzip-dev libonig-dev \
&& rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install intl zip opcache pdo_mysql bcmath
# Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# App code
WORKDIR /srv/app
COPY . /srv/app
RUN composer install --no-dev --optimize-autoloader --no-interaction
RUN php artisan config:cache route:cache view:cache
FROM base AS development
RUN pecl channel-update pecl.php.net \
&& pecl install xdebug-3.4.0 \
&& docker-php-ext-enable xdebug
COPY build/php/conf.d/xdebug.ini $PHP_INI_DIR/conf.d/xdebug.ini
This pattern follows the one‑minute Xdebug walkthrough from Laravel News, extended to a PHP‑FPM base instead of php:8.4-apache so we can put Traefik in front.
Configuring php-fpm.conf for Laravel
Create build/php/www.conf with pool settings tuned for a Laravel app of modest size:
[www]
user = www-data
group = www-data
listen = 0.0.0.0:9000
; Or for a Unix socket (preferred when Traefik shares the network namespace):
; listen = /run/php-fpm/www.sock
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
pm.status_path = /status
ping.path = /ping
Setting pm.max_requests = 500 forces PHP‑FPM to recycle workers, which prevents the slow memory creep that plagues long‑running Laravel queues.
docker-compose.yml: Services & Volumes
services:
php-fpm:
build:
context: .
target: development
volumes:
- .:/srv/app
networks: [internal]
environment:
XDEBUG_MODE: ${XDEBUG_MODE:-off}
traefik:
image: traefik:v3.1
command:
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
ports: ["80:80", "443:443"]
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks: [internal]
app:
image: your-registry/laravel-app:latest
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`app.example.com`)"
- "traefik.http.routers.app.entrypoints=websecure"
- "traefik.http.services.app.loadbalancer.server.port=9000"
networks: [internal]
networks:
internal:
driver: bridge
The HackerNoon production stack article shows a more elaborate setup with Horizon, Pulse, and the Scheduler split into separate containers, which is the right pattern at scale.
Optimizing Workers, Connections, and OPcache
Default PHP‑FPM settings are conservative and tuned for legacy PHP workloads. For Laravel, you can usually push further.
worker_processes & pm settings
The rule of thumb: pm.max_children = (available RAM in MB) / (average Laravel request peak in MB). A typical Laravel 11 request hovers around 40–80 MB resident, so on a 512 MB container that yields 6–12 children. For a 1 GB container, 16–20 is realistic. The Snyk PHP Docker guide provides a useful sizing framework for image and memory budgets.
OPcache & Zend OPcache Configuration
Drop a file at build/php/conf.d/opcache.ini:
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=192
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.max_wasted_percentage=10
opcache.validate_timestamps=0
opcache.revalidate_freq=2
opcache.fast_shutdown=1
opcache.save_comments=1
opcache.jit=tracing
opcache.jit_buffer_size=64M
This is the configuration the Laravel News OPcache in Docker article recommends, extended with JIT tracing enabled. In production, set opcache.validate_timestamps=0 so cached opcodes never re‑check disk; rely on a fresh image build to ship new code.
Memory Limits & PHP‑CLI vs PHP‑FPM
PHP‑CLI (used by php artisan, queue workers, Scheduler) and PHP‑FPM are separate SAPIs. CLI has no request timeout and uses different memory accounting. Don't share their memory_limit values: keep FPM at 256M and CLI at 512M for queue workers that may need to process large payloads.
How to Keep Debugging Without Exposing Data
Xdebug is the most useful tool a Laravel developer has, and the most dangerous one in production. Treat it like a loaded weapon.
Conditional Xdebug Activation via ENV
Use the XDEBUG_MODE environment variable, which Xdebug 3 reads natively. In compose.yaml:
environment:
XDEBUG_MODE: ${XDEBUG_MODE:-off}
XDEBUG_CONFIG: "client_host=host.docker.internal client_port=9003"
Set XDEBUG_MODE=debug in your local .env and leave it off in production. This is the pattern the Laravel News Xdebug walkthrough documents, and it works without rebuilding the image.
Xdebug Remote Settings for Docker
Your xdebug.ini:
xdebug.mode = debug
xdebug.start_with_request = trigger
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.trigger_value = PHPSTORM
xdebug.log = /tmp/xdebug.log
Using trigger mode plus the XDEBUG_SESSION cookie or ?XDEBUG_SESSION=PHPSTORM query string means debugging only happens when you ask for it, so normal traffic stays fast. The SitePoint Xdebug + PHPStorm + Vagrant tutorial covers the IDE side if you're using PHPStorm on a VM rather than Docker.
Using phpinfo() Safely
Never expose phpinfo() on a public route, even behind auth. The output leaks every environment variable, every loaded extension, and the full filesystem path. If you need to verify configuration, hit the Traefik‑protected admin path or curl from inside the container.
Routing Laravel to PHP‑FPM with Traefik
Traefik is the right reverse proxy for containerized PHP‑FPM because it discovers services through Docker labels and handles Let's Encrypt without extra glue.
Traefik Labels in docker-compose
The minimal label set for routing HTTPS traffic to a PHP‑FPM container:
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`app.example.com`)"
- "traefik.http.routers.app.entrypoints=websecure"
- "traefik.http.routers.app.tls.certresolver=letsencrypt"
- "traefik.http.services.app.loadbalancer.server.port=9000"
The reverse proxy must speak FastCGI to PHP‑FPM, which Traefik handles natively when the upstream port is 9000 and FastCGI transport is configured. If you prefer a more batteries‑included option, FrankenPHP on top of Caddy is an attractive alternative that bundles FastCGI handling and HTTP/3.
TLS & HTTP/2 Configuration
Traefik's default websecure entrypoint already negotiates HTTP/2 and HTTP/3. Add --entrypoints.websecure.http3=true to the Traefik command line to enable QUIC. For a TLS certificate, point the certresolver at the letsencrypt resolver you define in Traefik's static config.
Health Checks & Load Balancing
PHP‑FPM exposes /ping and /status endpoints when configured. Wire them into Traefik's health checker:
- "traefik.http.services.app.loadbalancer.healthcheck.path=/ping"
- "traefik.http.services.app.loadbalancer.healthcheck.interval=10s"
Traefik will mark a PHP‑FPM instance unhealthy and route around it when /ping stops responding, which is exactly what you want during deployments.
What to Expect in Different Scenarios
PHP‑FPM is the workhorse, but the surrounding choices matter. The table below shows real‑world tradeoffs.
| Setup | Best For | TTFB (typical) | Operational Cost |
|---|---|---|---|
| PHP‑FPM in Docker + Traefik | Most teams | 30–60 ms | Low |
| Native PHP‑FPM on host + Nginx | Bare‑metal, single‑tenant VPS | 25–50 ms | Medium (manual upgrades) |
| Laravel Octane (FrankenPHP/Swoole) | High RPS, latency‑sensitive APIs | 5–15 ms | High (long‑lived memory bugs) |
| Laravel Herd / DDEV / Lando | Local development only | N/A | Lowest |
Docker vs Native PHP‑FPM
Docker wins on reproducibility and rollback. Native wins on raw performance and direct hardware access. For a single‑server hobby project, native is fine; for anything that has multiple environments, Docker is worth the small overhead.
Traefik vs Caddy vs Nginx
Traefik is the easiest when you already use Docker labels. Caddy is the most pleasant to configure by hand, especially with FrankenPHP under the hood. Nginx is the most powerful and the most painful; pick it only if you need its rewrite logic and caching for legacy reasons.
Laravel Octane vs PHP‑FPM
Octane keeps Laravel booted in memory, which can drop TTFB by an order of magnitude. The cost is that any code that holds onto a reference (long‑lived static state, event listeners, Eloquent relationship caching) can leak across requests. PHP‑FPM's per‑request teardown is a feature, not a bug, for most applications.
Your Go‑to Checklist for Production
Run through this before declaring the stack production‑ready.
Security Hardening
- Run PHP‑FPM as a non‑root user; the
www-datadefault is fine inside a container. - Bind
listento a Unix socket when Traefik shares the network namespace, removing any TCP exposure. - Set
expose_php = Offinphp.inito suppress theX-Powered-Byheader. - Verify Xdebug is not in the production image with
php -m | grep -i xdebug.
Logging & Monitoring
- Stream PHP‑FPM logs to stdout so Docker's log driver picks them up.
- Expose
pm.status_path = /statusand scrape it with Prometheus. - Forward Laravel logs to a centralized aggregator (Loki, Datadog, New Relic).
Auto‑Scaling with Docker Compose
Docker Compose has a built‑in scale command: docker compose up --scale php-fpm=4. For real autoscaling, move to Swarm or Kubernetes, but for a single host this is the right level of complexity. The HackerNoon production stack guide demonstrates how to keep Horizon and the Scheduler as separate scaled services alongside the FPM containers.
CI/CD Integration
Your pipeline should build the production stage of the Dockerfile, run php artisan test against the development stage, and push only the slim production image. Snyk's PHP Docker hardening article has a useful scan‑the‑image step you can add to the pipeline.
Avoid These Pitfalls
Every team I've seen misconfigure PHP‑FPM has hit the same handful of bugs. Watch for these.
Leaving Xdebug Enabled
This is the most common mistake and the most damaging. An Xdebug‑enabled FPM container can leak stack traces through error responses, slow requests by 30–50%, and reveal environment variables to anyone who triggers a 500. Use the XDEBUG_MODE env var and verify with php -m | grep -i xdebug on the running production container.
Incorrect php-fpm.conf Paths
Inside the official PHP image, the pool directory is /usr/local/etc/php-fpm.d/, not /etc/php/8.4/fpm/pool.d/ as it is on Debian/Ubuntu. If you're copy‑pasting configs from a native install, the FPM master will silently ignore them. The Laravel News OPcache Docker article shows the right path conventions for the official images.
Container Restart Loops
If your container keeps restarting, the first place to look is pm.max_children: a value too high for the available memory triggers OOM kills, which Docker interprets as a crash and restarts. Start conservative, watch docker stats, and grow the pool gradually.
Choosing the Right Stack for Your Team
Different teams have different constraints. The matrix below matches the most common personas to the configuration that will save them the most time.
| Target Persona | Recommended Option | Key Reason & Real‑World Benefit |
|---|---|---|
| Solo developer, side project | Native PHP‑FPM + Caddy on a single VPS | Zero container overhead, two config files, deploys in seconds. |
| Small team (2–6 devs), SaaS | Docker + PHP‑FPM + Traefik + managed Postgres | One‑command onboarding, predictable staging, TLS handled for you. |
| Enterprise, microservices | Kubernetes + PHP‑FPM + Octane for hot paths | Horizontal scaling, canary deploys, language‑agnostic platform team. |
| CI/CD‑centric team | Docker Compose + Snyk + GH Actions | Reproducible builds, automated security scans, image promotion. |
Verdict: For 80% of Laravel teams in 2026, the answer is Docker + PHP‑FPM + Traefik. It is the lowest‑ops configuration that still gives you production realism, observability, and TLS out of the box. Pick Octane only when you have a measured latency problem, not a hypothetical one.
People Also Ask About PHP‑FPM for Laravel
Can I Use PHP‑FPM without Docker?
Absolutely. Install php8.4-fpm from your distro's package manager, edit /etc/php/8.4/fpm/pool.d/www.conf, and point Nginx or Apache's reverse proxy at port 9000. You lose container isolation but gain direct hardware access, which matters for some low‑latency workloads.
Do I Need Xdebug in Production?
No. Xdebug belongs in the development stage of your multi‑stage build only. The performance cost alone is reason enough: every request runs roughly 30% slower with Xdebug active, and error responses can include sensitive stack traces.
How to Update PHP‑FPM in Docker?
Bump the base image tag in your Dockerfile, rebuild, run your test suite, and redeploy. Because the production stage strips Xdebug and only contains the runtime extensions you actually use, image size stays small. The pattern the Laravel News Xdebug walkthrough uses is the right template for any PHP‑FPM upgrade.
Wrap‑Up: Is PHP‑FPM Worth It in 2026?
How to Configure PHP‑FPM for Laravel remains a non‑optional skill in 2026, and the configuration has only gotten more important as Laravel applications scale into multi‑container platforms. PHP‑FPM gives you the per‑request isolation that Octane sacrifices, the predictable memory profile that mod_php never offered, and the Docker/Traefik friendliness that modern infrastructure assumes.
Key Takeaways
- Use the
php:8.4-fpmbase image with a multi‑stage Dockerfile that strips Xdebug from production. - Tune
pm.max_childrento your container's memory, not the documented maximum. - Enable OPcache with JIT tracing and
opcache.validate_timestamps=0in production. - Wire Traefik labels in
docker-compose.ymlfor automatic HTTPS and health checks. - Never leave debugging tools in the production image, and verify with
php -m.
Next Steps & Resources
Read the HackerNoon production stack article for the multi‑container layout, the Laravel News OPcache guide for cache tuning, and the Snyk PHP Docker guide for security hardening. If you're coming from Homestead or Vagrant, the SitePoint Xdebug + PHPStorm walkthrough is still the best reference for IDE‑side configuration. Build the stack, run a load test, and watch TTFB drop.