In this tutorial, we will show you how to install Mattermost on Debian 11. For those of you who didn’t know, Mattermost is a self-hosted and open-source online chat service designed to be used as an internal chat platform for companies and organizations. It offers secure communication between teams and easier collaboration between individuals and groups. Mattermost makes data available between developers allowing them to access the source code and contribute directly to it in different locations because it is cloud-based.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you through the step-by-step installation of Mattermost open-source platform for developer collaboration on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Mattermost on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing the LEMP stack.
A Debian 11 LEMP server is required. If you do not have LAMP installed, Please read our previous tutorial to install LEMP Server on Debian 11.
Step 3. Configuring MariaDB for Mattermost.
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
mysql_secure_installation
Configure it like this:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
Next, we will need to log in to the MariaDB console and create a database for the Mattermost. Run the following command:
mysql -u root -p
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Mattermost installation:
MariaDB [(none)]> CREATE DATABASE mattermost_db; MariaDB [(none)]> CREATE USER 'mattermost_user' IDENTIFIED BY 'your-strong-password'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermost_db.* TO 'mattermost_user'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
Step 4. Installing Mattermost on Debian 11.
Before installing Mattermost, create a new user and group that will run our Mattermost server:
sudo useradd --system --user-group mattermost
By default, Mattermost is not available on Debian 11 base repository. So, now we download the latest stable version of Mattermost from the official page:
wget wget https://releases.mattermost.com/6.0.2/mattermost-6.0.2-linux-amd64.tar.gz
Next, extract the downloaded file:
tar xvzf mattermost-6.0.2-linux-amd64.tar.gz -C /opt/ sudo mkdir /opt/mattermost/data
We will need to change some folder permissions:
chown -R mattermost:mattermost /opt/mattermost chmod -R g+w /opt/mattermost
Step 5. Configure Mattermost.
Now we have to define certain parameters in the Mattermost configuration. Edit the Mattermost configuration file and define your site URL and database settings:
nano /opt/mattermost/config/config.json
Change the following lines:
"SiteURL": "http://mattermost.your-domian.com", "DriverName": "MySQL", "DataSource": "mmuser:your-strong-passwdD@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",
Step 6. Create a Systemd Service File for Mattermost.
We will set up systemd
a service to start and stop the Mattermost service:
nano /lib/systemd/system/mattermost.service
Add the following lines:
[Unit] Description=Mattermost After=network.target After=mysql.service Requires=mysql.service [Service] Type=notify User=mattermost Group=mattermost ExecStart=/opt/mattermost/bin/mattermost TimeoutStartSec=3600 Restart=always RestartSec=10 WorkingDirectory=/opt/mattermost LimitNOFILE=49152 [Install] WantedBy=mariadb.service
Save and close the file, then reload the systemd
daemon to apply the configuration changes:
sudo systemctl daemon-reload sudo systemctl start mattermost sudo systemctl enable mattermost
Step 6. Configure Nginx as a Reverse Proxy.
Now create an Nginx virtual host configuration file with the following command:
nano /etc/nginx/sites-available/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.your-domain; 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 65; send_timeout 200; lingering_timeout 5; proxy_connect_timeout 80; proxy_send_timeout 300; proxy_read_timeout 80s; 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 activate the virtual host configuration with the following command:
ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf sudo systemctl restart nginx
Step 7. Secure Mattermost with Let’s Encrypt SSL.
First, install Certbot to your Debian system using the following command below:
sudo apt install certbot python3-certbot-nginx
Then, generate the certificates, with the following command:
certbot --nginx -d mattermost.your-domian.com
You will then be prompted to enter an email address for the certificate. After you have entered that you must agree to the T&C’s and decide if you want to share your email address with the Electronic Frontier Foundation. This last step is optional. Once successfully, Reload Apache again to load all the new configurations.
Step 8. Accessing Mattermost Web Interface.
Once successfully installed, open your web browser and type the URL https://mattermost.your-domian.com
to access the Mattermost web UI. You should see the following screen:
Congratulations! You have successfully installed Mattermost. Thanks for using this tutorial for installing the latest version of Mattermost open-source platform for developer collaboration on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Mattermost website.