Skip to content

Migrating From FPM or Octane

Moving to PAM changes how your application is served, not how it is written. This guide lists what changes, side by side, and the gotchas worth checking before you switch production traffic.

Concern PHP-FPM + Nginx PAM
Entry point public/index.php per request pam.php, booted once per worker
Processes Nginx + FPM master + FPM children PAM master + workers
Concurrency pm.max_children pam start --workers N
Recycling pm.max_requests --max-requests N
Static files Nginx try_files A reverse proxy or CDN (recommended), or Laravel
Health Custom /live, /ready, /metrics on --admin-address
Reload systemctl reload php-fpm kill -HUP <master> (new generation, then drain)
Artisan php artisan pam artisan
Composer composer pam composer
  1. Add pam.php to the project root (Installation).

  2. Run your test suite under PAM:

    Terminal window
    pam artisan test
  3. Audit persistent state: search for static properties that hold per-request data, singletons built from the request or user, and setlocale()/ini_set() calls. See Request Lifecycle.

  4. Install the production tooling and turn on strict leak detection in staging:

    Terminal window
    pam composer require pushinbr/pam-laravel
    pam artisan pam:install --preset=api
    .env (staging)
    PAM_LARAVEL_STATE_GUARD_STRICT=true
  5. Run the persistent smoke test with your real routes.

  6. Put PAM behind your existing Nginx (keep it for TLS and static files):

    /etc/nginx/sites-available/example.com
    server {
    listen 443 ssl http2;
    server_name example.com;
    root /srv/app/current/public;
    location / {
    try_files $uri @pam;
    }
    location @pam {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }

    and trust the proxy in Laravel (bootstrap/app.php, $middleware->trustProxies(at: '127.0.0.1')) and in pam.php ('trustedProxies' => ['127.0.0.1']).

  7. Replace the FPM service with a PAM service (Deploying Laravel).

  • php.ini settings. PAM embeds its own PHP, so settings you tuned in FPM’s php.ini (memory_limit, upload_max_filesize, post_max_size) must be passed to PAM, before the command name, with -d or -c:

    Terminal window
    pam -d memory_limit=512M -d upload_max_filesize=64M start pam.php --workers 8
    pam -c /etc/pam/php.ini start pam.php --workers 8
  • Request size. maxBodyBytes (2 MiB by default) limits non-multipart bodies such as large JSON payloads. Raise it in pam.php if needed.

  • Timeouts. FPM’s request_terminate_timeout becomes requestTimeoutMs (30 s by default).

  • exit() and die() in application code do not just end the request: the client receives a 500 and PAM recycles the worker. Return a response or throw an exception instead (abort(403)).

  • Deploys. pam start runs OPcache with validate_timestamps=0. Code changes take effect after a reload, never mid-generation.

You have two options.

Keep your Octane code and use PAM as the server:

Terminal window
pam composer require pushinbr/pam-octane
pam artisan octane:install --server=pam
pam octane:start

Octane’s lifecycle events, listeners, Octane::concurrently(), tables, and ticks keep working. See Laravel Octane on PAM.

Octane Without Octane on PAM
octane:start --workers=N pam start pam.php --workers N
--max-requests --max-requests
octane:reload kill -HUP <master>
Octane::concurrently() Requires the Octane bridge with --task-workers
Octane tables and octane cache Requires the Octane bridge
RequestReceived / RequestTerminated listeners LifecycleHook from pushinbr/pam-laravel
Octane’s flush list in config/octane.php scoped() bindings, or a LifecycleHook

The rules for safe code are the same in both worlds: Octane and PAM both keep the application in memory, so code that is already Octane-safe is PAM-safe.