How can I configure Laravel websocket on digitalocean without using forge
So, I have a real time app which is working fine locally, but moving it to production I realize the real time feature is no longer working mainly because of Laravel websocket error: "WebSocket is closed before the connection is established."
"WebSocket connection to 'wss://mirrorlog.com/app/*******?protocol=7&client=js&version=7.0.6&flash=false' failed: "
I've been making lots of research about this, but most are just referring to forge.
My app is hosted on digital ocean
Your help would be appreciated
Have you added SSL certificate details in websockets configuration file?
I was facing same issue and after 3 days of juggling with configuration, this worked for me. (Digitalocean / Ubuntu / Apache).
websockets.php
....
'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null), // Add this variable in .env file
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null), // Add this variable in .env file
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
'verify_peer' => false, //Don't forget to add this line.
],
....
.env
....
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/letsencrypt/live/yourdomain.com/fullchain.pem"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/letsencrypt/live/yourdomain.com/privkey.pem"
LARAVEL_WEBSOCKETS_SSL_PASSPHRASE="YourPassPhraseIfAny"
boradcasting.php
...
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => 'yourdomain.com', // 127.0.0.1 didn't worked for me
'port' => 6001,
'scheme' => 'https',
'encrypted' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
'client_options' => [
],
],
...
Try running php artisan websocket:serve with sudo user or run sudo php artisan websocket:serve. If you are using supervisor run the supervisor with sudo user.
Also make sure that your SSL certificate files are accessible and have read permission.
@rajatpatelz thank you do much.
But can you please explain how I can generate these keys:
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/letsencrypt/live/yourdomain.com/fullchain.pem" LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/letsencrypt/live/yourdomain.com/privkey.pem" LARAVEL_WEBSOCKETS_SSL_PASSPHRASE="YourPassPhraseIfAny
I use cloudflare for SSL
Sorry I can't help you with that, better google it.
Have you added SSL certificate details in websockets configuration file?
I was facing same issue and after 3 days of juggling with configuration, this worked for me. (Digitalocean / Ubuntu / Apache).
websockets.php
.... 'ssl' => [ 'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null), // Add this variable in .env file 'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null), // Add this variable in .env file 'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null), 'verify_peer' => false, //Don't forget to add this line. ], .....env
.... LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/letsencrypt/live/yourdomain.com/fullchain.pem" LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/letsencrypt/live/yourdomain.com/privkey.pem" LARAVEL_WEBSOCKETS_SSL_PASSPHRASE="YourPassPhraseIfAny"boradcasting.php
... 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ 'cluster' => env('PUSHER_APP_CLUSTER'), 'host' => 'yourdomain.com', // 127.0.0.1 didn't worked for me 'port' => 6001, 'scheme' => 'https', 'encrypted' => true, 'curl_options' => [ CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, ] ], 'client_options' => [ ], ], ...Try running
php artisan websocket:servewith sudo user or runsudo php artisan websocket:serve. If you are using supervisor run the supervisor with sudo user. Also make sure that your SSL certificate files are accessible and have read permission.
ily bro
Have you added SSL certificate details in websockets configuration file?
I was facing same issue and after 3 days of juggling with configuration, this worked for me. (Digitalocean / Ubuntu / Apache).
websockets.php
.... 'ssl' => [ 'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null), // Add this variable in .env file 'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null), // Add this variable in .env file 'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null), 'verify_peer' => false, //Don't forget to add this line. ], .....env
.... LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/letsencrypt/live/yourdomain.com/fullchain.pem" LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/letsencrypt/live/yourdomain.com/privkey.pem" LARAVEL_WEBSOCKETS_SSL_PASSPHRASE="YourPassPhraseIfAny"boradcasting.php
... 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ 'cluster' => env('PUSHER_APP_CLUSTER'), 'host' => 'yourdomain.com', // 127.0.0.1 didn't worked for me 'port' => 6001, 'scheme' => 'https', 'encrypted' => true, 'curl_options' => [ CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, ] ], 'client_options' => [ ], ], ...Try running
php artisan websocket:servewith sudo user or runsudo php artisan websocket:serve. If you are using supervisor run the supervisor with sudo user. Also make sure that your SSL certificate files are accessible and have read permission.
Thanks men it works! it is my 3rd day now exploring this issue
'verify_peer' => false, //Don't forget to add this line.
Nobody ever talked about that. After a few days debugging, now it works, thanks a lot!!