Chat
4. Deployment

Example 2: Laravel Forge

Example 2: Deploying on Laravel Forge

On Laravel Forge, your server runs Nginx, PHP-FPM, Redis, and Supervisor on a dedicated VPS (e.g., DigitalOcean, AWS, Hetzner). To run tokomono/chat, you need to enable Reverb, configure a Queue Worker (or Horizon), and update your Deployment Script.


Step 1: Enable Laravel Reverb on Forge

  1. Open your site in the Laravel Forge dashboard and navigate to the Application (or Reverb) tab.
  2. Enable Laravel Reverb:
    • Set the Host (e.g., your site domain app.yourdomain.com or a dedicated subdomain ws.yourdomain.com) and internal Port (e.g., 8080).
    • Forge automatically configures the Nginx reverse proxy block (/app and /apps proxied to http://127.0.0.1:8080 with WebSocket Upgrade headers), provisions SSL via Let's Encrypt, and creates a Supervisor daemon running php artisan reverb:start.
  3. Verify that your Forge .env contains the matching credentials:
    BROADCAST_CONNECTION=reverb
    
    REVERB_APP_ID=123456
    REVERB_APP_KEY=your-forge-reverb-key
    REVERB_APP_SECRET=your-forge-reverb-secret
    REVERB_HOST="app.yourdomain.com"
    REVERB_PORT=443
    REVERB_SCHEME=https
    REVERB_SERVER_HOST=127.0.0.1
    REVERB_SERVER_PORT=8080
    
    VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
    VITE_REVERB_HOST="${REVERB_HOST}"
    VITE_REVERB_PORT="${REVERB_PORT}"
    VITE_REVERB_SCHEME="${REVERB_SCHEME}"
    
    QUEUE_CONNECTION=redis
    CHAT_QUEUE=chat
    CHAT_ATTACHMENTS_DISK=public
    CHAT_DEBUG=false
    

Step 2: Configure the Queue Worker or Horizon Daemon

You can run the chat queue on Forge in two ways:

Option A: Forge Queue Worker (Standard)

Go to your site's Queue tab in Forge and create a new worker:

  • Connection: redis
  • Queue: chat,default
  • Maximum Seconds Per Job (Timeout): 120
  • Maximum Tries: 1
  • Processes: 3

Option B: Laravel Horizon (Recommended)

  1. Ensure supervisor-chat is defined in config/horizon.php with 'queue' => ['chat'] and 'timeout' => 120.
  2. In the Forge Server -> Daemons tab, add a daemon:
    • Command: php8.3 artisan horizon
    • Directory: /home/forge/app.yourdomain.com
    • User: forge

Step 3: Forge Deployment Script (deploy.sh)

Update your site's Deploy Script in Laravel Forge so that frontend assets are built, the public storage symlink exists for chat attachments, migrations run, and both Horizon/Queue workers and Reverb are gracefully restarted on every deploy:

cd $FORGE_SITE_PATH

git pull origin $FORGE_SITE_BRANCH

$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader

npm ci
npm run build

$FORGE_PHP artisan storage:link
$FORGE_PHP artisan migrate --force

$FORGE_PHP artisan config:cache
$FORGE_PHP artisan route:cache
$FORGE_PHP artisan view:cache
$FORGE_PHP artisan event:cache

# Restart Queue Workers / Horizon & Reverb WebSocket Server
$FORGE_PHP artisan horizon:terminate || $FORGE_PHP artisan queue:restart
$FORGE_PHP artisan reverb:restart