Configure the built-in Web Sockets server

Use the built-in web sockets server to receive real-time updates and notifications.

In this article we will discuss how to configure the built-in Web Sockets server provided by the help desk. The Web Sockets server allows real-time communication between the server and the client (browser).

The built-in Web Sockets server requires a highly flexible server, like a VPS, SSH acess and Root or Sudo privileges. If you are using Full Help on a shared-hosting and don't have what's needed, feel free to use the Pusher integration.

What you will need

  1. SSH access to your server
  2. Root or sudo access (sudo is recommended)
  3. Queues set up and working
  4. Supervisor installed on your server

For this guide, we assume that the help desk is installed at /var/www/fullhelp/live.

In order for the Web Socket server to listen on new connections, the php artisan websockets:serve command should be executed at the root directory of the installation. Note that once the websockets:serve command has started, it will continue to run until it is manually stopped or you close your terminal.

To keep the websockets:serve process running permanently in the background, we will use the process monitor, Supervisor, to ensure that the built-in web sockets server worker does not stop running.

Enable the Built-In Web Socket Server

To enable the built-in web socket server, simply add BROADCAST_DRIVER=builtin to the .env file, located at the root directory of your help desk application. Make sure there's only one BROADCAST_DRIVER configuration on the file.

Supervisor Configuration

Installing Supervisor

Supervisor is a process monitor for the Linux operating system, and will automatically restart your websockets:serve process if it fails. To install Supervisor on Ubuntu, you may use the following command:

sudo apt-get install supervisor

Configuring Supervisor

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a fullhelp.conf file that starts and monitors a websockets:serve process:

[program:fullhelp-ws-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/fullhelp/live/artisan websockets:serve --port=6001
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/fullhelp/live/storage/logs/worker.log

Make sure to replace /var/www/fullhelp/live with the path to your own installation. --port can also be changed based on your needs, 6001 is the default port used by the built-in web sockets server. If you select a port other than 6001, make sure to add PUSHER_PORT=your-port to the .env file.

Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start fullhelp-ws-worker:*

For more information on Supervisor, consult the Supervisor documentation.

SSL Configuration

If you have configured HTTPS for your help desk software, it is also crucial to secure the WebSockets server. Adding SSL support is easy.

These are high-level instructions and should be adapted to each environment. In most cases, SSL is provided by Let's Encrypt, so we are going to use it as an example.

First, add the following settings to the .env file:

  • WEBSOCKETS_LOCAL_CERT: Path to local certificate file on the filesystem. It must be a PEM encoded file which contains your certificate and private key. It can optionally contain the certificate chain of issuers. The private key also may be contained in a separate file specified by WEBSOCKETS_LOCAL_PRIVATE_KEY.
  • WEBSOCKETS_LOCAL_PRIVATE_KEY: Path to the local private key file on the filesystem in case of separate files for the certificate (WEBSOCKETS_LOCAL_CERT) and private key.

See the following example:

WEBSOCKETS_LOCAL_CERT="/etc/letsencrypt/live/desk.mydomain.com/fullchain.pem"
WEBSOCKETS_LOCAL_PRIVATE_KEY="/etc/letsencrypt/live/desk.mydomain.com/privkey.pem"
Please note: the user running the websocket:serve command should have access to read the certificate files. It's common that the certificate files are owned by the root user, in which case, the root user should also run the websocket:serve command — something we do not recommend. You can change the certificate owner user and run the command under that user username.

Once you add the certificate file paths, enable HTTPS for WebSocket connections by adding the following to the .env file:

PUSHER_ENCRYPTED=true
PUSHER_SCHEME=https

A note to CloudFlare users:

The port 6001 will not work when using CloudFlare Proxy. Change it to one of the allowed secure ports, like 2053. Remember to update the supervisor configuration for the websocket:serve command and the .env file.

Troubleshooting

The built-in Web Sockets server may not work correctly for several reasons, the most common ones are:

  1. lack of privileges
  2. firewall protection
  3. not being able to use the port specified
  4. Web Sockets server not started
  5. Incorrect BROADCAST_DRIVER configuration value, see the Enable the Built-In Web Socket Server section

Determining the real cause of a problem and the solution will vary considerably by what server is in use and the configurations.

Your vote was sent, thanks!
Was this article helpful?

Want to talk to a human?

Feel free to contact us if you cannot find what you are looking for in our help center. We will be answering you shortly!

Feel free to contact us if you cannot find what you are looking for in our help center. We will be answering you shortly!

Contact us
Woman messaging on mobile phone