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:
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
- Navigate to your Forge dashboard
- Create a new server using your preferred cloud provider
- Choose “App Server” as the server type
- Select appropriate server size (basic tier works for testing)
- Wait for server provisioning to complete
Site Configuration
After server provisioning:
- Add a new site using your domain (e.g.,
your-domain.com
) - Connect your GitHub repository to deploy your application
- 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
- Go to your site’s Application section in Forge
- Find the “Laravel Reverb” toggle
- Configure the public hostname (defaults to
ws.your-domain.com
) - Adjust max concurrent connections if needed
- 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
- Navigate to the SSL section of your site
- Use Let’s Encrypt to obtain certificates for both domains:
your-domain.com
ws.your-domain.com
- 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:
- Trigger a new deployment in Forge
- This will:
- Rebuild assets with
npm run build
- Restart the Reverb daemon
- Apply new configuration
- Rebuild assets with
Verify Connection
Open your application and check the browser’s Network tab:
- Filter by WebSocket connections
- Look for a connection with status 101 (successful WebSocket handshake)
- 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:
- Proper DNS configuration for both main domain and WebSocket subdomain
- SSL certificate setup for secure connections
- Environment variable updates for production settings
- 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.