computergeek's avatar

Laravel Reverb deployment to producton

So, I have this Laravel 10 application where I added reverb to handle the response to the user after the queue is done processing. It works perfectly locally but when I deploy it to digital ocean, I get the following error. So the frontend cant listen to events.

app-755bd30d.js:13 WebSocket connection to 'wss://abc.org/app/j9v8xrlmq0z0aw5hmysn?protocol=7&client=js&version=8.4.0-rc2&flash=false' failed: createWebSocket @ app-755bd30d.js:13.

How can I go about this problem?

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue with WebSocket connections failing in your Laravel application when deployed to production on Digital Ocean, you need to ensure that your WebSocket server is correctly configured and accessible. Here are the steps to troubleshoot and resolve the problem:

  1. Check WebSocket Server Configuration: Ensure that your WebSocket server (e.g., Laravel Echo Server, Pusher, etc.) is correctly configured and running. If you are using Laravel Echo Server, your laravel-echo-server.json configuration file should be properly set up.

  2. Update Environment Variables: Make sure your environment variables in the .env file are correctly set for production. For example, if you are using Pusher, you need to set the correct Pusher credentials:

    BROADCAST_DRIVER=pusher
    PUSHER_APP_ID=your-pusher-app-id
    PUSHER_APP_KEY=your-pusher-app-key
    PUSHER_APP_SECRET=your-pusher-app-secret
    PUSHER_APP_CLUSTER=your-pusher-app-cluster
    
  3. Ensure SSL/TLS Configuration: Since you are using wss:// (WebSocket Secure), ensure that your server has a valid SSL certificate. You can use Let's Encrypt for free SSL certificates.

  4. Configure Nginx/Apache: If you are using Nginx or Apache as your web server, you need to configure it to handle WebSocket connections. Here is an example configuration for Nginx:

    Adjust the proxy_pass directives to match the ports your Laravel application and WebSocket server are running on.

  5. Firewall and Security Groups: Ensure that the necessary ports are open in your firewall and security groups. Typically, port 6001 is used for WebSocket connections.

  6. Check Browser Console: Look at the browser console for more detailed error messages. This can provide additional clues about what might be going wrong.

By following these steps, you should be able to resolve the WebSocket connection issue in your Laravel application when deployed to production. If you continue to experience problems, please provide more details about your setup and any additional error messages you are seeing.

Please or to participate in this conversation.