# Websocket server installation

If you have a VPS/VDS, you can set up your own web socket server with Soketi (opens new window).
If you don't have this option, you can use the Pusher API (opens new window).

# Install Soketi on a same server

# Prepare nginx configuration

  1. Open main nginx config (usually path is /etc/nginx/nginx.conf)
  2. Paste the following code into the http section:
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
  1. Open your domain configuration file.
  2. Paste the following code to the bottom and save it (opens new window):
server {
    # Comment if using an ssl certificate.
    listen 2096 http2;
    listen [::]:2096 http2;
    
    # Uncomment if using an ssl certificate.
    # listen 2096 ssl http2;
    # listen [::]:2096 ssl http2;
    
    server_name your_domain.com;
    server_tokens off;
    root /path/to/your/forum;
    index index.php;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    
    # Uncomment if using an ssl certificate.
    # ssl         on;
    # ssl_certificate      /path/to/your/certificate.pem;
    # ssl_certificate_key  /path/to/your/certificate.key;

    charset utf-8;

    location / {
        proxy_pass             http://127.0.0.1:6001;
        proxy_read_timeout     60;
        proxy_connect_timeout  60;
        proxy_redirect         off;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
  1. Restart nginx:
service nginx restart

# Install and configure Soketi

Go to the forum directory:

cd /path/to/your/forum

Create a config for Soketi:

php cmd.php xf-websockets:create-soketi-config

Now you need to choose how you want to run the websocket server - directly on the server or in a docker container. The docker container allows you to avoid conflicts with the environment settings and run the server even on OSes that are not compatible with Soketi (such as CentOS 7).
To run the server in a docker container, Docker (opens new window) must be installed on the server.

# Install Soketi directly on the server

bash websockets install-soketi

# Install Soketi image for Docker container

bash websockets pull-docker-image

Run a daemon after this. Choose one of the options below.

# Run a daemon using systemd

# Daemon to run Soketi directly on the server

bash websockets install-systemd-service your_domain.com

# Daemon to run Soketi in a docker container

bash websockets install-systemd-service your_domain.com --docker

Now you can check the status of the daemon with the command:

systemctl status soketi.your_domain.com

# Run a daemon using supervisor

# Service to run Soketi directly on the server

bash websockets install-supervisor-service your_domain.com

# Service to run Soketi in a docker container

bash websockets install-supervisor-service your_domain.com --docker

Now you can check the status of the daemon with the command:

supervisorctl status soketi.your_domain.com

# Install Soketi on a separate server

Prepare your nginx configuration as described in the nginx configuration manual.

  1. Connect to the forum server.

  2. Go to the forum directory:

    cd /path/to/your/forum
    
  3. Create a config for Soketi:

    php cmd.php xf-websockets:create-soketi-config
    
  4. Connect to the server where you want to run Soketi.

  5. Upload the websockets file from the addon archive to the server.

  6. Go to the directory where you uploaded the file:

    cd /path/to/your/websockets/file
    
  7. Create src directory.

    mkdir src
    
  8. Upload the src/soketi.config.json file from the forum root directory to the src directory on the server.

  9. Install Soketi directly or in Docker.

  10. Run a daemon after this. Choose one of these options.

  11. Open XenForo WebSockets options: ACP > Setup > Options > [021] XenForo WebSockets.

  12. Paste the server IP or domain with protocol into the Pusher host field. For example: https://your_domain.com.

# Use Pusher API

  1. Create an account on Pusher (opens new window).
  2. Go to the Dashboard (opens new window) and click on the "Get started" button in the "Channels" section.
  3. Create a new app:
    You can name it as you want.
    Choose the cluster that is closest to your server.
    The rest of the options don't matter.
  4. Go to the "App Keys" tab.
  5. Open XenForo WebSockets options: ACP > Setup > Options > [021] XenForo WebSockets.
  6. Paste the values from the "App Keys" tab into the corresponding fields.
  7. Save the options.