@hal.littel
To run a Laravel Websocket Server on Heroku, follow these steps:
- Create a new Laravel application by running the command:
1
|
composer create-project --prefer-dist laravel/laravel example-app
|
- Install the laravel-websocket package by running:
1
|
composer require beyondcode/laravel-websockets
|
- Publish the configuration file by running:
1
|
php artisan vendor:publish --provider="BeyondCodeLaravelWebSocketsWebSocketsServiceProvider" --tag="config"
|
- Add your Heroku app URL to the trusted_proxies array in the websockets.php configuration file:
1
2
3
4
5
|
'trusted_proxies' => [
'192.168.1.1',
'10.0.0.1',
'proxy-url-on-heroku.com',
],
|
- Modify your broadcasting.php configuration file to use the pusher driver provided by the laravel-websockets package:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => null,
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => false,
'host' => 'your-heroku-app-url',
'port' => 6001,
'scheme' => 'http',
],
],
],
|
- Create a Procfile in the root directory of your Laravel application with the following content:
1
|
web: bin/start-socket.sh
|
- Create a bin/start-socket.sh file with the following content:
1
|
php artisan websockets:serve
|
- Commit your changes to your git repository and then deploy your Laravel application to Heroku.
- Scale your worker dyno on Heroku by running the following command:
1
|
heroku ps:scale web=1:free worker=1:free
|
- Run the Websockets serve command on Heroku by running:
1
|
heroku run php artisan websockets:serve
|
Your Laravel Websocket server should now be up and running on Heroku. You can test the functionality by connecting to your websocket server from a client application.