Install websockets in laravel easy steps

Install websockets in laravel-10 easy steps

Install websockets in laravel-10 easy steps

WebSockets in Laravel refer to a real-time communication protocol that enables bidirectional communication between a client (usually a web browser) and a server over a single, long-lived connection. Unlike traditional HTTP requests, WebSockets allow continuous data exchange without the need for constant request-response cycles, making them ideal for real-time applications such as chat applications, notifications, and collaborative tools.now we start install websockets in laravel-10 easy steps

Install websockets in laravel easy steps

Step:1 You need to run a command in command prompt to install websocket in your laravel project

composer require beyondcode/laravel-websockets

Step:2 You need to following commands

1. php artisan vendor:publish –provider=”BeyondCode\LaravelWebSockets\WebSocketsServiceProvider” –tag=”migrations”2. php artisan migrate

3. php artisan vendor:publish –provider=”BeyondCode\LaravelWebSockets\WebSocketsServiceProvider” –tag=”config”

4. composer require pusher/pusher-php-server “~3.0”

after running these command create a file websockets.php inside config folder

Step:3 You need to add some settings to env file show below

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:HMpAZfca8ieBSg9NuIFigO2jMRCFEpxgg6GMMWdzBFs=
APP_DEBUG=true
APP_URL=http://localhostLOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debugDB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myevents
DB_USERNAME=root
DB_PASSWORD=BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120MEMCACHED_HOST=127.0.0.1REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=”hello@example.com”
MAIL_FROM_NAME=”${APP_NAME}”AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=54544545
PUSHER_APP_KEY=JHGTRFERT
PUSHER_APP_SECRET=HGTTTREDSDDWE
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=http
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME=”${APP_NAME}”
VITE_PUSHER_APP_KEY=”${PUSHER_APP_KEY}”
VITE_PUSHER_HOST=”${PUSHER_HOST}”
VITE_PUSHER_PORT=”${PUSHER_PORT}”
VITE_PUSHER_SCHEME=”${PUSHER_SCHEME}”
VITE_PUSHER_APP_CLUSTER=”${PUSHER_APP_CLUSTER}”

Step:4 run following command

php artisan websockets:serve

hit the url “http://127.0.0.1:8000/laravel-websockets” in browser and click on connect

Install websockets in laravel-10 easy steps

 

Leave a Reply

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