Laravel

Reverb

Run Laravel Reverb, Laravel's WebSocket server, as its own container from the same image as your web service. Unlike the other workers, Reverb listens on a port, so your reverse proxy needs a route to it.

Spin Pro sets up Laravel Reverb on your own server with zero-downtime deployments.

Install and configure Reverb in your application first, following Laravel's Reverb docs. The stop signal and health check follow the same rules as every other worker. See Running workers.

Compose example with Traefik

This example routes app.example.com to the web service on port 8080 and reverb.example.com to Reverb on port 8000.

compose.yml
services:
  app:
    image: my-org/my-app:1.0.0
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.laravel.tls=true"
      - "traefik.http.routers.laravel.entrypoints=websecure"
      - "traefik.http.routers.laravel.rule=Host(`app.example.com`)"
      - "traefik.http.services.laravel.loadbalancer.server.port=8080"
      - "traefik.http.services.laravel.loadbalancer.server.scheme=http"

  reverb:
    image: my-org/my-app:1.0.0
    command: ["php", "artisan", "reverb:start", "--port=8000"]
    stop_signal: SIGTERM
    healthcheck:
      test: ["CMD", "healthcheck-reverb"]
      start_period: 10s
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.reverb.tls=true"
      - "traefik.http.routers.reverb.entrypoints=websecure"
      - "traefik.http.routers.reverb.rule=Host(`reverb.example.com`)"
      - "traefik.http.services.reverb.loadbalancer.server.port=8000"
      - "traefik.http.services.reverb.loadbalancer.server.scheme=http"

Client variables point at the proxy, not the container

Reverb reads two sets of variables. The REVERB_SERVER_* variables configure the Reverb process inside the container. The REVERB_HOST, REVERB_PORT, and REVERB_SCHEME variables tell clients where to connect: browsers, and your application when it broadcasts an event. They must match the public address that Traefik serves.

VariableValue for the example above
REVERB_HOSTreverb.example.com
REVERB_PORT443
REVERB_SCHEMEhttps

Don't set REVERB_PORT to 8000. Clients would then connect to the container port, which Traefik doesn't expose.