How to run Laravel Websockets in production (ubuntu + apache2)?

4.4k Views Asked by At

I'm using the Laravel Websockets package https://beyondco.de/docs/laravel-websockets/getting-started/introduction.

In my local dev server I run it using php artisan websockets:server and it works fine, but I would like to know how can I run it in my production server (Ubuntu + Apache2).

2

There are 2 best solutions below

5
On

After run your websocket server, you need proxypass to your apache. like below config:

<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName your.domain.com
ProxyPass / http://localhost:6001/
ProxyPassReverse / http://localhost:6001/
</VirtualHost>

change 6001 to your websocket port.

To run in background you need to add your websocket server in backround using nohup or pm2 . example:

pm2 start "php artisan websockets:server"

or using nohup

nohup php artisan websockets:server
0
On

You can use supervisord , you can install and have configuration file to run command php artisan web socket:serve