How to Install Mattermost on Ubuntu 22.04

install mattermost on ubuntu 22.04

Mattermost is an open-source communication and collaboration platform for businesses, organizations, and technical and operational teams. It’s a secure and private alternative to other messaging platforms like Slack and Microsoft Teams.

With Mattermost, you have a rich ecosystem of third-party tools which you can integrate, and you can host your own messaging server, have full control over your data, and customize the platform to your specific needs.

In this tutorial, we will show you how to install Mattermost on Ubuntu 22.04. Also, you can check out our tutorial on installing Mattermost on Ubuntu 20.04.

Step 1: Update Ubuntu Packages

Before installing any new package on your Ubuntu 20.04 server, updating the packages is always a good idea.

To do so, run the following command:

# apt update && sudo apt upgrade

Step 2: Install PostgreSQL

You can use MySQL or PostgreSQL as a database server; for this tutorial, you are going to use 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 command:

sudo -u postgres psql

Now go ahead and create a new database and PostgreSQL user who will have full permissions to this database

postgres=# CREATE DATABASE mattermost;.
postgres=# CREATE USER matuser WITH PASSWORD 'secure-password';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to matuser;
postgres=# \q

Step 3: Install Mattermost

Download the latest version of Mattermost from the official website using the following command:

# wget https://releases.mattermost.com/7.8.1/mattermost-7.8.1-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 you favorite 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://matuser:strong-password@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",

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

[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 can start the Mattermost service

# 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:

# 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 don’t forget 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 over your domain https://your-domain.com. If you found this article helpful and were able to install Mattermost on your Ubuntu 22.04 server, please consider sharing the knowledge on social media or the Internet. You can also leave a comment if you want to show appreciation or if you have any better methods of installing Mattermost. Thank you!

Leave a Comment