An open-source messaging system, Mattermost provides a secure and flexible chat service with features like file sharing, a search function, and integrations. With its user-friendly interface, Mattermost is easy to use and is becoming more popular. It is a no-cost substitute for platforms like Slack, Microsoft Teams, and similar services. This tutorial will show you how to install Mattermost on Debian 12.
Table of Contents
Prerequisites to Install Mattermost on Debian 12
- A Debian 12 VPS with at least 2GB of RAM
- SSH access with sudo privileges or root access.
Conventions
# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user
Step 1. Log in to your server via SSH
First, you will need to log in to your Debian 12 VPS via SSH as the root user:
ssh root@IP_Address -p Port_number
You must replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.
You can check whether you have the proper Debian version installed on your server with the following command:
# lsb_release -a
The command should return an output like this:
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
In this article, we use ‘root’ to execute the shell commands. If you want to use your regular user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands.
Step 2. Update the system
Before starting, we need to ensure that all Debian 12 packages installed on the server are up to date. You can do this by running the following commands:
# apt update
The list of available packages in the system package index has been refreshed. Let’s proceed to the next step.
Step 3. Create User
The Mattermost service will be run by another system user, and not root. In this step, we will create a new system user called “mattermost”. Let’s execute the command below, you can substitute ‘mattermost’ with any username you like.
# useradd -mrd /opt/mattermost mattermost -s "$(which bash)"
The command above will automatically create the directory /opt/mattermost as the home directory for user ‘mattermost’. We will use this directory for the Mattermost installation path.
Step 4. Install PostgreSQL
At the moment, Mattermost supports both PostgreSQL 11.0+ and MySQL 8.0.12+. In this step, we are going to install PostgreSQL as the database server for Mattermost. Let’s complete this step by simply running the following command:
# apt install postgresql
Once the installation is finished, PostgreSQL will be automatically up and running. It is also configured to automatically run upon a server reboot.
Step 5. Create a Database
Next, let’s create a PostgreSQL database. First, we need to log in to user ‘postgres’ and then go to PostgreSQL shell
# su - postgres
$ psql
Once logged in, let’s run these commands below to create a database, user, and then grant the user access.
CREATE DATABASE mattermost;
CREATE USER mattermost WITH PASSWORD 'm0d1fyth15';
GRANT ALL ON DATABASE mattermost TO mattermost;
ALTER DATABASE mattermost OWNER TO mattermost;
GRANT USAGE, CREATE ON SCHEMA PUBLIC TO mattermost;
Next, quit from PostgreSQL shell, then exit from postgres user
\q
$ exit
Step 6. Download and Install Mattermost
In the earlier step, we created a system user called ‘Mattermost’; let’s switch to this user account and download Mattermost. If you want to download the more recent tarball package, you can go to their download page and get the download link
# su - mattermost
$ wget https://releases.mattermost.com/9.5.6/mattermost-9.5.6-linux-amd64.tar.gz -O mattermost.tar.gz
The installation file has been downloaded and saved as mattermost.tar.gz. Now, let’s extract the file.
$ tar -xzvf mattermost.tar.gz --strip-component 1
Before running Mattermost, we need to configure it to connect to our database.
$ cp /opt/mattermost/config/config.json{,.orig}
The command above is to save a copy of config.json as config.json.orig. Now, let’s edit the config.json file to connect to the PostgreSQL database.
$ nano /opt/mattermost/config/config.json
Configure the following properties in this file:
Set DataSource to "dbuser:@:3306/dbname?sslmode=disable\u0026connect_timeout=10\u0026binary_parameters=yes",
replace dbuser, dbpassword with your dbuser and dbpassword you created in the previous step. In this case, it would be:
"DataSource": "postgres://mattermost:m0d1fyth15@localhost/mattermost?sslmode=disable\u0026connect_timeout=10\u0026binary_parameters=yes",
Set your “SiteURL”: The domain name for the Mattermost application (e.g. https://mattermost.yourdomain.com).
save the file then exit from nano editor then exit from user ‘mattermost’
$ exit
Step 7. Create Systemd Service File
In this step, we will create a systemd service file to manage our Mattermost service. Let’s create a systemd service file for Mattermost now.
# nano /etc/systemd/system/mattermost.service
Paste the following into the systemd service file, then save it.
[Unit]
Description=Mattermost
After=network.target
[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
KillMode=mixed
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target
Save the file, exit, and then reload systemd for changes to take effect.
# systemctl daemon-reload
Next, let’s enable Mattermost to run on boot and run the service now.
# systemctl enable --now mattermost
The command above will return an output like this:
Created symlink /etc/systemd/system/multi-user.target.wants/mattermost.service → /etc/systemd/system/mattermost.service.
At this point, Mattermost should be up and running, and it will automatically run on boot. To verify, run this command:
# systemctl status mattermost
You will see an output similar to this
● mattermost.service - Mattermost
Loaded: loaded (/etc/systemd/system/mattermost.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-06-19 06:47:49 CDT; 2min 4s ago
Main PID: 6289 (mattermost)
Tasks: 38 (limit: 4644)
Memory: 328.8M
CPU: 26.288s
CGroup: /system.slice/mattermost.service
├─6289 /opt/mattermost/bin/mattermost
├─6314 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
├─6323 plugins/com.mattermost.calls/server/dist/plugin-linux-amd64
└─6331 plugins/playbooks/server/dist/plugin-linux-amd64
Jun 19 21:18:01 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:01.957 -04:00","level":"info","msg":"got public IP address for>
Jun 19 21:18:01 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:01.957 -04:00","level":"info","msg":"rtc: server is listening >
Jun 19 21:18:01 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:01.959 -04:00","level":"info","msg":"rtc: server is listening >
Jun 19 21:18:01 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:01.961 -04:00","level":"info","msg":"Listening TCP on 0.0.0.0:>
Jun 19 21:18:02 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:02.660 -04:00","level":"info","msg":"Starting Server...","call>
Jun 19 21:18:02 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:02.664 -04:00","level":"info","msg":"Server is listening on [:>
Jun 19 21:18:02 localhost.localdomain mattermost[55973]: {"timestamp":"2023-09-14 21:18:02.664 -04:00","level":"info","msg":"Sending systemd READY not>
Jun 19 21:18:02 localhost.localdomain systemd[1]: Started Mattermost.
You should be able to access Mattermost at http://YOUR_SERVER_IP_ADDRESS:8065
Step 8. Install and Configure Nginx
In the previous step, we managed to access Mattermost at http://YOUR_SERVER_IP_ADDRESS:8065. To access Mattermost through a domain or subdomain without using the port at the end of the URL, we need to install and configure a reverse proxy. Let’s install and configure nginx.
# apt install nginx -y
Once installed, we can create an nginx server block for our Mattermost website.
# nano /etc/nginx/conf.d/mattermost.conf
Then, insert the following into the file.
upstream backend {
server 127.0.0.1:8065;
}
server {
listen 80;
server_name mattermost.yourdomain.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_http_version 1.1;
proxy_pass http://backend;
}
location / {
client_max_body_size 50M;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
proxy_read_timeout 600s;
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://backend;
}
}
Save the file, then exit from the editor and restart nginx
# systemctl restart nginx
That’s it, you should be able to access Mattermost at http://mattermost.yourdomain.com now.
Congratulations! You learned how to install Mattermost on Debian 12
You followed this article, and now you have successfully installed Mattermost on your Debian 12 server.
Of course, you don’t have to spend your time following this article to install Mattermost on Debian 12 if you have an active Debian 12 VPS Hosting service with us, in which case you can ask our expert Linux admins to install Mattermost for you. Log in to the client area, then submit a ticket. Our admins are available 24×7 and will respond to your request immediately. They will also help you install an SSL certificate on your Mattermost server.
If you liked this post on how to install Mattermost on Debian 12, please share it with your friends and leave a comment below. Thanks.