How to Install Mattermost on Ubuntu 24.04

How to install Mattermost on Ubuntu 24.04

Mattermost is an open-source collaboration and messaging platform designed for team communication. It’s a secure and private alternative to other team collaboration and communication platforms such as Microsoft Teams and Slack. It offers many features, such as private and public communication channels, direct messaging, media and file sharing, and threaded messages. It can also be integrated with other tools like GitHub, Jira, etc. This tutorial will show you how to install Mattermost on Ubuntu 24.04. Let’s get started!

Step 1: Update Ubuntu Packages

Before you start the installation on your Mattermost server, update the packages first. You can do this with the following command:

apt update && sudo apt upgrade

Step 2: Install PostgreSQL

The Mattermost application supports both PostgreSQL and MySQL database servers. In this tutorial, we will show you how to install PostgreSQL as a database server for Mattermost. You can install PostgreSQL using the following command:

# apt install postgresql postgresql-contrib

Once the installation is completed, you can access PostgreSQL using the commands:

# su postgres
$ psql

Now, create a new database and a PostgreSQL user with full permissions to this database and the public schema.

postgres=# CREATE DATABASE mattermost;
postgres=# CREATE USER matteruser WITH PASSWORD 'your-secure-password';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to matteruser;
postgres=# GRANT ALL ON DATABASE mattermost TO matteruser;
postgres=# ALTER DATABASE mattermost OWNER TO matteruser;
postgres=# GRANT USAGE, CREATE ON SCHEMA PUBLIC TO matteruser;
postgres=# \q

Step 3: Install Mattermost

Download the latest version of Mattermost on your server by using the following command below. Please note at the time of writing, the latest version of Mattermost was 9.9.0:

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

Extract the downloaded archive using the following command:

tar -xvf mattermost*.tar.gz

Move the extracted directory to the /opt directory using the following command:

# mv mattermost /opt/mattermost

Step 4: Configure Mattermost

First, create a new system user called Mattermost using the following command:

useradd -U -M -d /opt/mattermost mattermost

Change the owner and group of the Mattermost directory to Mattermost using the command:

# chown -R mattermost:mattermost /opt/mattermost

Now, you open your favorite text editor and edit the configuration file for Mattermost.

nano /opt/mattermost/config/config.json

You will need to edit the following line according to your database username, password, and database name:

"DataSource": "postgres://matteruser:strong-password@localhost/mattermost?sslmode=disable\u0026connect_timeout=10\u0026binary_parameters=yes",

Now you can create the systemd unit file for the Mattermost service at /etc/systemd/system/mattermost.service

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
[Unit]
Description=Mattermost
After=network.target
After=postgresql.service
BindsTo=postgresql.service

[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

Reload the system daemon, and you can start the Mattermost service now.

# systemctl daemon-reload

# systemctl start mattermost

You can also enable the Mattermost service to start automatically with every system reboot

# systemctl enable mattermost

To confirm that Mattermost is installed and everything is working as expected, you can run the following:

systemctl status mattermost

● mattermost.service - Mattermost
Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2023-03-14 12:08:12 UTC; 2h 17min ago
Main PID: 11725 (mattermost)
Tasks: 40 (limit: 4573)
Memory: 273.2M
CPU: 16.264s
CGroup: /system.slice/mattermost.service
├─11725 /opt/mattermost/bin/mattermost
├─11743 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
├─11748 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
├─11761 plugins/playbooks/server/dist/plugin-linux-amd64
├─11774 plugins/focalboard/server/dist/plugin-linux-amd64
└─11789 plugins/com.mattermost.calls/server/dist/plugin-linux-amd64

Mattermost is now installed and running. To access Mattermost, open your favorite browser and enter http://server-IP-address:8065
To access Mattermost using your domain, you will need to install nginx and set up a reverse proxy for port 8065

# apt install nginx

Create the virtual host file by replacing your-domain with your actual domain.

# nano /etc/nginx/sites-available/your-domain.com.conf

Use the following code for the virtual host configuration file, and remember to replace your domain with your actual domain name.

server {

    listen 80;    
    server_name your-domain.com;
    root /opt/mattermost;

    error_log /var/log/nginx/mattermost.error;
    access_log /var/log/nginx/mattermost.access;

           location / {

    proxy_pass http://localhost:8065;

    }
}

Now Mattermost can be accessed on your domain: http://your-domain.com. If you found this article helpful and learned how to install Mattermost on Ubuntu 24.04, please consider sharing the knowledge with your friends. You can also leave a comment if you want to show appreciation or if you have any better methods of installing Mattermost. Thanks!

Leave a Comment