Example 1: Laravel Cloud
Example 1: Deploying on Laravel Cloud
Laravel Cloud provides managed WebSockets (Reverb) clusters, Managed Queues, Laravel Valkey (Redis), and Cloudflare R2 Object Storage, making it the fastest way to run tokomono/chat in production without managing daemons or Nginx proxies manually.
Step 1: Attach Required Cloud Resources
In your Laravel Cloud environment (via the dashboard or ./vendor/bin/cloud CLI), provision and attach:
- Database Cluster (MySQL or PostgreSQL) — stores
agent_conversationsandagent_conversation_messages. - Cache / Valkey (Redis) — required for rate limiting, draft conversation caching, and queues.
- WebSocket Cluster (Laravel Reverb) — attaches a managed Reverb server to your environment and automatically injects
REVERB_APP_ID,REVERB_APP_KEY,REVERB_APP_SECRET,REVERB_HOST,REVERB_PORT,REVERB_SCHEME, and the correspondingVITE_REVERB_*variables. - Cloud Object Storage (Public Bucket) — because Laravel Cloud filesystems are ephemeral and not shared across replicas, create a public Object Storage bucket, attach it with the disk name
public, and install the S3 Flysystem adapter:composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies
Step 2: Configure Environment Variables
Add the following variables to your Laravel Cloud environment (leaving the auto-injected REVERB_* and DB_* variables intact):
BROADCAST_CONNECTION=reverb
CHAT_QUEUE=chat
CHAT_ATTACHMENTS_DISK=public
CHAT_DEBUG=false
OPENAI_API_KEY=sk-...
Step 3: Enable Managed Queues for the chat Queue
In your Laravel Cloud environment compute configuration, configure a Queue Worker (or Managed Queue cluster):
- Queues:
chat,default(or a dedicated worker forchat) - Timeout:
120seconds (must be greater thanProcessChatTurnJob::$timeoutof110seconds) - Tries:
1
Note: Avoid scale-to-zero (hibernating) compute without managed queues if your AI workflows run for extended periods, so active streaming jobs are never interrupted mid-turn.
Step 4: Configure Build & Deploy Commands
In your environment's Build & Deploy settings on Laravel Cloud:
Build Command
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader && npm ci && npm run build
Deploy Command
php artisan migrate --force
Tip: Do not add
php artisan storage:link,php artisan queue:restart,php artisan horizon:terminate, orphp artisan reverb:restartto your Laravel Cloud deploy command. Laravel Cloud automatically restarts workers and manages WebSocket clusters on every release.