Skip to content

Deploying Laravel

A production Laravel deployment on PAM has the same moving parts on every platform:

  1. Build an immutable release: dependencies, framework caches, migrations.
  2. Run the HTTP cluster (pam start pam.php) and, separately, queue workers and the scheduler.
  3. Gate traffic on the admin /ready endpoint.
  4. Reload with SIGHUP to switch to new code with zero downtime.
Terminal window
pam composer install --no-dev --classmap-authoritative --no-interaction
pam artisan optimize
pam artisan migrate --force

Then check the result:

Terminal window
pam artisan pam:check-production
Terminal window
APP_ENV=production \
PAM_HOST=127.0.0.1 \
PAM_PORT=3000 \
pam start pam.php \
--workers 8 \
--max-requests 1000000 \
--admin-address 127.0.0.1:3010
Pam control plane listening on http://127.0.0.1:3010
● READY Pam listening on http://127.0.0.1:3000 worker=1
...
Pam master 989965 started 8 worker(s); send SIGHUP for zero-downtime reload

Useful flags (full list in the reference):

Flag Purpose
--workers N Worker processes (one Laravel request each)
--max-requests N Recycle a worker after about N requests
--admin-address IP:PORT /live, /startup, /ready, /metrics
--graceful-timeout MS How long draining workers may finish in-flight requests
--startup-timeout MS How long a new worker may take to become ready

Send SIGHUP to the master:

Terminal window
kill -HUP <master-pid> # or: systemctl reload example-app
Pam master activated worker generation 2

PAM boots a complete new generation from the current code, waits until it is ready, then drains the old generation. The listening socket belongs to the master, so no connection is refused. Because workers run OPcache with validate_timestamps=0, new code is only picked up by a reload.

The typical release flow with a current symlink:

Terminal window
cd /srv/app/releases/20261202-1500
pam composer install --no-dev --classmap-authoritative --no-interaction
pam artisan optimize
pam artisan migrate --force
ln -sfn /srv/app/releases/20261202-1500 /srv/app/current.next
mv -T /srv/app/current.next /srv/app/current
systemctl reload example-app
pam artisan queue:restart

Roll back by pointing current at the previous release and reloading again.

Run each role as its own unit.

/etc/systemd/system/example-app.service
[Unit]
Description=Example app (PAM HTTP)
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/srv/app/current
Environment=APP_ENV=production
Environment=PAM_HOST=127.0.0.1
Environment=PAM_PORT=3000
Environment=PAM_LARAVEL_STORAGE_PATH=/var/lib/example-app
EnvironmentFile=-/etc/example-app/pam.env
ExecStart=/usr/local/bin/pam start pam.php --workers 8 --max-requests 1000000 --admin-address 127.0.0.1:3010
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
KillMode=mixed
TimeoutStopSec=45s
Restart=always
RestartSec=2s
LimitNOFILE=1048576
StateDirectory=example-app
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
[Install]
WantedBy=multi-user.target
/etc/systemd/system/example-app-queue.service
[Unit]
Description=Example app (queue worker)
After=network-online.target
[Service]
User=www-data
WorkingDirectory=/srv/app/current
Environment=APP_ENV=production
ExecStart=/usr/local/bin/pam artisan queue:work --sleep=1 --tries=3 --max-time=3600
Restart=always
RestartSec=2s
[Install]
WantedBy=multi-user.target
/etc/systemd/system/example-app-scheduler.service
[Unit]
Description=Example app (scheduler)
After=network-online.target
[Service]
User=www-data
WorkingDirectory=/srv/app/current
Environment=APP_ENV=production
ExecStart=/usr/local/bin/pam artisan schedule:work
Restart=always
[Install]
WantedBy=multi-user.target
Terminal window
systemctl daemon-reload
systemctl enable --now example-app example-app-queue example-app-scheduler
systemctl reload example-app # zero-downtime deploy

ProtectSystem=strict makes the release read-only; StateDirectory= creates /var/lib/example-app, which PAM_LARAVEL_STORAGE_PATH points Laravel’s storage at. Build bootstrap/cache during the release; add ReadWritePaths= for any other directory the app writes to.

Dockerfile
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
ENV PAM_INSTALL_DIR=/opt/pam PAM_BIN_DIR=/usr/local/bin
RUN curl -fsSL https://pamphp.com/install | sh \
&& pam --version
WORKDIR /app
COPY . .
RUN pam composer install --no-dev --classmap-authoritative --no-interaction \
&& chown -R www-data:www-data storage bootstrap/cache
USER www-data
ENV APP_ENV=production APP_DEBUG=false PAM_HOST=0.0.0.0 PAM_PORT=8000
EXPOSE 8000
HEALTHCHECK --interval=10s --timeout=3s CMD curl -fsS http://127.0.0.1:3010/ready || exit 1
CMD ["sh", "-c", "pam artisan optimize && exec pam start pam.php --workers ${PAM_WORKERS:-4} --admin-address 127.0.0.1:3010"]
.dockerignore
vendor
node_modules
.env
storage/logs/*
.git
Terminal window
docker build -t example-app .
docker run --rm -p 8000:8000 --env-file .env.production example-app

pam artisan optimize runs at container start so the configuration cache sees the runtime environment. PAM_HOST=0.0.0.0 is required inside a container; the admin listener stays on the container’s loopback for the health check.

Run queue workers and the scheduler from the same image with a different command:

compose.yaml
services:
app:
build: .
env_file: .env.production
ports: ["8000:8000"]
queue:
build: .
env_file: .env.production
command: ["pam", "artisan", "queue:work", "--sleep=1", "--tries=3", "--max-time=3600"]
scheduler:
build: .
env_file: .env.production
command: ["pam", "artisan", "schedule:work"]
deploy/kubernetes.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
spec:
replicas: 2
selector:
matchLabels: { app: example-app }
template:
metadata:
labels: { app: example-app }
spec:
containers:
- name: app
image: registry.example.com/example-app:2026.12.02
env:
- { name: PAM_HOST, value: "0.0.0.0" }
- { name: PAM_PORT, value: "8000" }
- { name: PAM_WORKERS, value: "2" }
ports: [{ containerPort: 8000 }]
readinessProbe:
httpGet: { path: /up, port: 8000 }
livenessProbe:
httpGet: { path: /up, port: 8000 }
initialDelaySeconds: 10
resources:
requests: { cpu: 500m, memory: 512Mi }
limits: { cpu: "2", memory: 1Gi }

The admin listener is on loopback, so probe Laravel’s own /up health route (or /__pam/health with pushinbr/pam-laravel) through the application port. Match PAM_WORKERS to the CPU limit, and run queue and scheduler Deployments from the same image with their own command.

Create the site as usual, then:

  1. Daemons. Add three daemons in the site’s directory: the HTTP cluster (pam start pam.php --workers 4 --admin-address 127.0.0.1:3010, with PAM_PORT set in the environment), pam artisan queue:work, and pam artisan schedule:work (or Forge’s scheduler with pam artisan schedule:run).
  2. Nginx. Proxy the site to 127.0.0.1:$PAM_PORT as shown in Migrating From FPM.
  3. Deploy script. Use PAM for Composer and Artisan, then reload:
Forge deploy script
$CREATE_RELEASE()
cd $FORGE_RELEASE_DIRECTORY
pam composer install --no-dev --no-interaction --prefer-dist --classmap-authoritative
pam artisan optimize
pam artisan migrate --force --no-interaction
$ACTIVATE_RELEASE()
$RESTART_QUEUES()

Then restart the HTTP daemon from Forge (or send it SIGHUP) so the new release is loaded. See PAM Cloud & Forge for deployment webhooks.

For a single server without systemd units, PAM can supervise the HTTP cluster itself with a declarative pam.toml:

pam.toml
schema_version = 1
[applications.example-http]
kind_code = 1
script = "pam.php"
workers = 4
cwd = "."
env_file = ".env"
health_check_url = "http://127.0.0.1:3000/up"
auto_restart = true
Terminal window
pam config:check pam.toml
pam plan pam.toml
pam apply pam.toml
pam ps

The environment file must belong to you and have mode 0600 or stricter. Kind 2 runs Laravel Octane. pam apply waits for each application to become ready, which a queue worker never does, so supervise queue workers and the scheduler with systemd or your platform instead.

pushinbr/pam-laravel can activate a prepared release directory:

Terminal window
export PAM_DEPLOY_ROOT=/srv/app/releases
export PAM_DEPLOY_CURRENT=/srv/app/current
export PAM_DEPLOY_READINESS_URL=http://127.0.0.1:3010/ready
pam artisan pam:deploy /srv/app/releases/20261202-1500 --local
pam artisan pam:deploy --local --rollback

pam:deploy checks that the release is inside PAM_DEPLOY_ROOT and contains artisan and composer.lock, runs pam artisan optimize and (unless PAM_DEPLOY_MIGRATE=false) pam artisan migrate --force inside it, swaps the current symlink atomically, then polls the readiness URL for up to PAM_DEPLOY_READINESS_TIMEOUT seconds. If readiness fails, the previous symlink target is restored. The previous target is stored in $PAM_DEPLOY_ROOT/.pam-previous for --rollback.

It does not signal the PAM master. Reload the cluster yourself after activation (for example with systemctl reload example-app).