Deploy Laravel Reverb to Production with Laravel Forge: Complete Setup Guide

Deploy Laravel Reverb to Production with Laravel Forge: Complete Setup Guide

Learn how to deploy Laravel Reverb for real-time WebSocket connections on Laravel Forge. Step-by-step guide covering SSL, DNS, and production configuration.

Laravel Reverb brings native WebSocket support to Laravel applications, enabling real-time features like chat systems and live notifications. While setting up Reverb locally is straightforward, deploying it to production requires careful configuration of WebSocket servers, SSL certificates, and DNS records.

This guide walks you through deploying a Laravel Reverb application to production using Laravel Forge, covering everything from initial server setup to SSL configuration.

Prerequisites

Before starting, ensure you have:

  • A Laravel application with Reverb installed
  • A Laravel Forge account
  • A domain name with DNS management access
  • GitHub repository containing your application

Setting Up Your Local Development Environment

First, clone your application and set up the local environment:

git clone your-repo-url 
cd your-project composer 
install npm install

Since this example uses SQLite, create the database file:
bash
touch database/database.sqlite
php artisan migrate
npm run dev

Start Reverb locally to verify everything works:

php artisan reverb:start --debug

Test your real-time functionality locally before proceeding to production deployment.

Creating Your Production Server on Forge

Server Provisioning

  1. Navigate to your Forge dashboard
  2. Create a new server using your preferred cloud provider
  3. Choose “App Server” as the server type
  4. Select appropriate server size (basic tier works for testing)
  5. Wait for server provisioning to complete

Site Configuration

After server provisioning:

  1. Add a new site using your domain (e.g., your-domain.com)
  2. Connect your GitHub repository to deploy your application
  3. Install the repository

Repository Deployment

Configure your deploy script to include asset building:

composer install --no-interaction --prefer-dist --optimize-autoloader
npm install
npm run build
php artisan migrate --force

DNS Configuration

Configure DNS records for both your main domain and WebSocket subdomain:

Main Domain

Create an A record pointing to your server’s IP address:

Type: A 
Name: @ 
Value: [Your Server IP]

WebSocket Subdomain

Create a CNAME record for the WebSocket subdomain:

Type: CNAME
Name: ws 
Value: your-domain.com

Wait for DNS propagation before proceeding.

Enabling Laravel Reverb on Forge

Forge simplifies Reverb setup significantly compared to manual configuration.

Toggle Reverb Service

  1. Go to your site’s Application section in Forge
  2. Find the “Laravel Reverb” toggle
  3. Configure the public hostname (defaults to ws.your-domain.com)
  4. Adjust max concurrent connections if needed
  5. Click “Start Laravel Reverb”

Forge automatically:

  • Creates a daemon process for Reverb
  • Configures the WebSocket server
  • Updates environment variables
  • Sets up process monitoring

Verify Daemon Creation

Check the Daemon section in your server dashboard. You’ll see a new daemon running:

php8.2 artisan reverb:start --no-interaction --port=8080

SSL Certificate Configuration

WebSocket connections require SSL in production environments.

Obtain SSL Certificate

  1. Navigate to the SSL section of your site
  2. Use Let’s Encrypt to obtain certificates for both domains:
    • your-domain.com
    • ws.your-domain.com
  3. Click “Obtain Certificate”

Note: Disable Cloudflare proxy temporarily if you encounter certificate issues.

Update Environment Configuration

After SSL setup, update your environment variables:

#Forge would have already configured the other Reverb settings.
REVERB_PORT=443
REVERB_SCHEME=https

Save changes and clear the configuration cache.

Final Deployment and Testing

Rebuild Assets and Restart Services

Since you’ve changed WebSocket configuration, rebuild your JavaScript assets to include the new settings:

  1. Trigger a new deployment in Forge
  2. This will:
    • Rebuild assets with npm run build
    • Restart the Reverb daemon
    • Apply new configuration

Verify Connection

Open your application and check the browser’s Network tab:

  1. Filter by WebSocket connections
  2. Look for a connection with status 101 (successful WebSocket handshake)
  3. Test your real-time features

Common Configuration Issues

WebSocket Connection Failures

  • Verify DNS records are properly configured
  • Ensure SSL certificates cover both main domain and WebSocket subdomain
  • Check that the Reverb daemon is running in Forge

Asset Build Problems

  • Confirm npm run build is included in your deploy script
  • Verify Vite configuration includes correct WebSocket settings
  • Check that environment variables are properly set

SSL Certificate Issues

  • Temporarily disable Cloudflare proxy during certificate generation
  • Ensure both domains are included in the certificate request
  • Verify DNS records are propagated before certificate generation

Production Best Practices

Security Considerations

  • Use environment variables for sensitive configuration
  • Implement proper authentication for WebSocket connections
  • Consider rate limiting for broadcast endpoints

Performance Optimization

  • Adjust max concurrent connections based on expected load
  • Monitor server resources and scale as needed
  • Implement connection cleanup for disconnected clients

Monitoring and Debugging

  • Use Forge’s daemon monitoring to track Reverb service health
  • Implement logging for WebSocket events
  • Set up alerts for service failures

Conclusion

Laravel Forge significantly simplifies Laravel Reverb deployment by automating daemon creation, environment configuration, and service management. The key steps are:

  1. Proper DNS configuration for both main domain and WebSocket subdomain
  2. SSL certificate setup for secure connections
  3. Environment variable updates for production settings
  4. Asset rebuilding to include new WebSocket configuration

With this setup, your Laravel application can handle real-time WebSocket connections in production, enabling features like live chat, notifications, and collaborative editing.

The combination of Laravel Reverb and Forge provides a robust foundation for real-time applications without the complexity of managing WebSocket servers manually.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.