How to Install Mattermost on Debian 11

Mattermost is a free and open-source collaboration and messaging platform created with security in mind. It is an alternative to Discord or Slack and offers many useful features including, one-to-one messaging, unlimited search history and file-sharing capabilities, two-factor authorization, and notifications. It is a self-hosted online chat service written in Golang and React. It is specially designed for organizations and companies and allows teams to communicate securely from everywhere.

In this tutorial, we will show you how to install the Mattermost Chat server on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Install and Configure MariaDB Database Server

Mattermost uses MySQL or MariaDB as a database backend. So you will need to install the MariaDB server to your server. You can install it using the following command:

apt-get install mariadb-server -y

Once the MariaDB is installed, start the MariaDB service and enable it to start at system reboot:

systemctl start mariadb
systemctl enable mariadb

Next, connect to the MariaDB shell with the following command:

mysql

Once you are connected, create a database and user with the following command:

MariaDB [(none)]> create database mattermost;
MariaDB [(none)]> create user mattermost@localhost identified by 'password';

Next, grant all the privileges to the Mattermost database with the following command:

MariaDB [(none)]> grant all privileges on mattermost.* to mattermost@localhost;

Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Once you are finished, you can proceed to the next step.

Install Mattermost

First, create a dedicated user for Mattermost using the following command:

useradd --system --user-group mattermost

Next, download the latest version of Mattermost with the following command:

wget https://releases.mattermost.com/6.0.2/mattermost-6.0.2-linux-amd64.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvzf mattermost-6.0.2-linux-amd64.tar.gz

Next, move the extracted directory to the /opt with the following command:

mv mattermost /opt

Next, create a data directory for mattermost using the following command:

mkdir /opt/mattermost/data

Next, change the ownership of the mattermost directory with the following command:

chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost

Next, edit the config.json file with the following command:

nano /opt/mattermost/config/config.json

Find the following lines:

    "DriverName": "postgres",
    "DataSource": "postgres://mmuser:mostest@localhost/mattermost_test?sslmode=disable\u0026connect_timeout=10",

And, replaced them with the following lines as per your database settings:

"DriverName": "mysql",
"DataSource": "mattermost:password@tcp(127.0.0.1:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",

Save and close the file when you are finished.

Create a Systemd Service File for Mattermost

Next, you will need to create a systemd service file for Mattermost. You can create it using the following command:

nano /etc/systemd/system/mattermost.service

Add the following lines:

[Unit]
Description=Mattermost
After=syslog.target network.target mysqld.service

[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
ExecStart=/opt/mattermost/bin/mattermost
PIDFile=/var/spool/mattermost/pid/master.pid
TimeoutStartSec=3600
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

Save and close the file then reload the systemd daemon to apply the changes:

systemctl daemon-reload

Next, start the Mattermost and enable it to start at system reboot:

systemctl start mattermost
systemctl enable mattermost

Next, verify the status of the Mattermost with the following command:

systemctl status mattermost

You will get the following output:

? mattermost.service - Mattermost
     Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-11-12 13:56:25 UTC; 4s ago
   Main PID: 2888 (mattermost)
      Tasks: 31 (limit: 4679)
     Memory: 273.3M
        CPU: 12.191s
     CGroup: /system.slice/mattermost.service
             ??2888 /opt/mattermost/bin/mattermost
             ??2915 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
             ??2925 plugins/playbooks/server/dist/plugin-linux-amd64
             ??2931 plugins/focalboard/server/dist/plugin-linux-amd64

Nov 12 13:56:24 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:24.681 Z","level":"info","msg":"Scheduling next survey for Dec 3, 2>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.064 Z","level":"info","msg":"Post.Message has size restrictions">
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.084 Z","level":"info","msg":"info [2021-11-12 13:56:25.083 Z] co>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.131 Z","level":"info","msg":"\n    -- collation of mattermost's >
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.491 Z","level":"info","msg":"debug [2021-11-12 13:56:25.488 Z] i>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.777 Z","level":"info","msg":"info [2021-11-12 13:56:25.777 Z] Se>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.963 Z","level":"info","msg":"Starting Server...","caller":"app/s>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.964 Z","level":"info","msg":"Server is listening on [::]:8065",">
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.964 Z","level":"info","msg":"Sending systemd READY notification.>
Nov 12 13:56:25 debian11 systemd[1]: Started Mattermost.

Configure Nginx as a Reverse Proxy for Mattermost

By default, Mattermost listens on port 8065. So it is a good idea to install and configure the Nginx as a reverse proxy to access the Mattermost on port 80. First, install the Nginx with the following command:

apt-get install nginx -y

Once the Nginx is installed, create an Nginx virtual host configuration file with the following command:

nano /etc/nginx/conf.d/mattermost.conf

Add the following lines:

upstream mattermost {
   server localhost:8065;
   keepalive 32;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;

server {
   listen 80;
   server_name mattermost.example.com;

   location ~ /api/v[0-9]+/(users/)?websocket$ {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size 50M;
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       client_body_timeout 60;
       send_timeout 300;
       lingering_timeout 5;
       proxy_connect_timeout 90;
       proxy_send_timeout 300;
       proxy_read_timeout 90s;
       proxy_pass http://mattermost;
   }

   location / {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       proxy_cache mattermost_cache;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://mattermost;
   }
}

Save and close the file then verify the Nginx configuration for any syntax error with the following command:

nginx -t

You should see the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, start the Nginx service to apply the changes:

systemctl start nginx

You can also verify the status of the Nginx using the following command:

systemctl status nginx

You should get the following output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-11-12 13:57:02 UTC; 1min 12s ago
       Docs: man:nginx(8)
    Process: 3384 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 3392 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 3602 (nginx)
      Tasks: 3 (limit: 4679)
     Memory: 6.6M
        CPU: 55ms
     CGroup: /system.slice/nginx.service
             ??3602 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??3604 nginx: worker process
             ??3605 nginx: worker process

Nov 12 13:57:01 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 12 13:57:02 debian11 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Nov 12 13:57:02 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.

At this point, Nginx is installed and configured as a reverse proxy for Mattermost. You can now proceed to the next step.

Access Mattermost Web Interface

Now, open your web browser and access the Mattermost web interface using the URL http://mattermost.example.com. You will be redirected to the following page:

Mattermost Login

Provide your admin email address, username, password, and click on the Create Account button. You should see the following page:

Mattermost

Now, click on the Go to System Console. You will be redirected to the Mattermost dashboard as shown below:

Mattermost dashboard

Conclusion

Congratulations! you have successfully installed the Mattermost with Nginx as a reverse proxy on Debian 11. You can now implement Mattermost in your organization and allow teams to communicate with each other from everywhere.

Share this page:

2 Comment(s)