Running Laravel Websockets in production — Setting up websockets for a single application

Setting up websockets for a single application

This is a continuation of the ‘Running Laravel Websockets in production’ tutorial series. This tutorial is part of a 4 part series, as shown below.

  1. Setting up a websockets for a single application. — This article

If you haven’t looked at the previous tutorial which includes setting up the initial configurations i.e., the web sockets server itself and supervisor kindly read it .


This deployment model is the most common and basically what we are interested in is having one web sockets server, serving just one application.

Single application approach

In this approach, we will be connecting the client browser using echo JS specifically pusher to our websockets running on .

In the above instance, both the Laravel application and websockets application will be running on the same domain. Replace the with your own domain/IP.


  • Easier to debug.
  • Simpler configurations required.
  • Easier to set up.


  • Serves only one application.

Step 1 — Customizing supervisor

This has already been mentioned in the first article. I’ll just put the config files for reference purpose.

command=php artisan websockets:serve --host --port 6000
user=[user] ;e.g. admin

After setting this configuration you can simply start supervisor by running service supervisor restart or if the service is not running then simply run service supervisor start

To check if your websockets is running, then use the command supervisorctl statusor service supervisor status

Please note we are running the websockets from localhost, this is by design in that we will proxy the requests from clients to the websockets running on localhost.

Step 2 — Setting up reverse proxy

This is the most important step, and you should read this carefully.

We will be setting up reverse proxies for apache2 and nginx.

As a general tip, we are simply proxying the request to our websockets server being served on as defined on the supervisor config above.


The following will be the configuration for nginx. Add the following configuration to your existing Laravel app nginx configuration.

...location /app/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
location /apps/ {
proxy_pass http:;
proxy_set_header Host $host;

For example, the configuration below is for our site

Nginx conf


For apache make sure that the apache mod_proxy is enabled, a tutorial on how to do this can be found . Add the following configuration to your existing web application configuration.

...ProxyPass "/app/" "ws://"
ProxyPass "/apps/" ""

For our example website, the configuration will be.

General warnings and tips

As a general tip, your app should avoid using the app/ and the apps/ route to avoid conflicts with the websockets server.

Step 3 — Laravel config files.

This shows the configurations for the Laravel web project.


There will be no change to the default websockets.conf file



A dedicated script file for echo js


You should have a running web socket application by now. If you are interested in another deployment model, choose from one below.



Freelance developer interested in natural simulations, visualization systems, and anything nerdy.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

Freelance developer interested in natural simulations, visualization systems, and anything nerdy.