DEV Community

Prathamesh Patil
Prathamesh Patil

Posted on

Websocket - With Socket.io & Lravel echo

As we all know about web-sockets ,as some times it may go difficult to implement. Here I will Mention the Perfect Simplified steps to implement a Web-socket for Front-end I have chosen Veu.js

Here we are going to Use Redis - So First We have to Install Redis pon our system



sudo apt install redis-server


Enter fullscreen mode Exit fullscreen mode

Lets Start with Laravel

Step 1: Install Following Packages



 i)composer require predis/predis,
 ii)composer require illuminate/redis


Enter fullscreen mode Exit fullscreen mode

Step 2: Add Following Line in .env file



REDIS_HOST = localhost
REDIS_PASSWORD = null
REDIS_PORT = 6379
REDIS_DB = 0

BROADCAST_DRIVER=redis


Enter fullscreen mode Exit fullscreen mode

Step 3:Now Install laravel-echo-server globally with command



npm install -g laravel-echo-server


Enter fullscreen mode Exit fullscreen mode

Step 4: Now in your Projects Root Folder run following command



laravel-echo-server init


Enter fullscreen mode Exit fullscreen mode

After running above command it will ask you following questions - ans is appropriately as eg below is mine on local machine



? Do you want to run this server in development mode? Yes
? Which port would you like to serve from? 6001
? Which database would you like to use to store presence channel members? redis
? Enter the host of your Laravel authentication server. http://localhost
? Will you be serving on http or https? http
? Do you want to generate a client ID/Key for HTTP API? No
? Do you want to setup cross domain access to the API? No
? What do you want this config to be saved as? laravel-echo-server.json



Enter fullscreen mode Exit fullscreen mode

Step 5: - Now start the Laravel Echo Server By command



laravel-echo-server start 


Enter fullscreen mode Exit fullscreen mode

This will look like below :-

Alt Text

Top comments (0)