Install Mattermost on Ubuntu 22.04

This article is going to show you how to install Mattermost on Ubuntu 22.04. Mattermost is a self-hosted, open-source online chat service that includes file sharing, search, and integrations. It’s mostly marketed as an open-source alternative to Slack and Microsoft Teams as an internal chat for businesses and organizations.

How to Install Mattermost on Ubuntu 22.04

  • To Install Mattermost on Ubuntu 22.04, start by updating and upgrading your system.
sudo apt update
sudo apt -y upgrade

Install PostgreSQL Database Server

  • In this example we are going to use PostgreSQL. Run the following command to install PostgreSQL.
sudo apt install postgresql postgresql-contrib
  • Next run the command below to log in into the PostgreSQL you just installed above.
sudo --login --user postgres
  • Start the PostgreSQL terminal.
psql
  • Then create the Mattermost database/user using the command below.
CREATE DATABASE mattermost;
CREATE USER itnixpro WITH PASSWORD 'itnixprodemo';
GRANT ALL PRIVILEGES ON DATABASE mattermost to itnixpro;
\q

Sample

postgres@ubuntu:~$ psql
psql (14.2 (Ubuntu 14.2-1.pgdg20.04+1))
Type "help" for help.

postgres=# CREATE DATABASE mattermost;
CREATE DATABASE
postgres=# CREATE USER itnixpro WITH PASSWORD 'itnixprodemo';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to itnixpro;
GRANT
postgres=# \q
postgres@ubuntu:~$ exit
logout
  • You’ll need to create a mattermost system user and group to launch the service.
sudo useradd --system --user-group mattermost
  • Verify it is a system user using the command below.
id mattermost

Install Mattermost on Ubuntu 22.04

  • Navigate to the Mattermost website to check the latest version. Download Mattermost using the following command.
wget https://releases.mattermost.com/6.1.0/mattermost-6.1.0-linux-amd64.tar.gz
  • Then extract the downloaded package.
tar xvf mattermost-6.1.0-linux-amd64.tar.gz
  • Place the extracted file in the /opt directory.
sudo mv mattermost /opt
  • Next create a directory that will store user data for Mattermost.
sudo mkdir /opt/mattermost/data
  • Set ownership and permissions correctly using the command below.
sudo chown -R mattermost:mattermost /opt/mattermost
  • Give the /opt/mattermost directory write permission.
sudo chmod -R g+w /opt/mattermost

Configure Mattermost Server on Ubuntu 22.04

  • Set up the database driver by opening the file below.
sudo nano /opt/mattermost/config/config.json
  • Press Ctrl+W to Search for SqlSettings in the file.
  • Under SqlSettings change the DataSource part to look like the one below then save it. Note, make sure mmuser and StrongDBPassWord is the user and password you created in the database above.
"DriverName": "postgres",
"DataSource": "postgres://mmuser:StrongDBPassWord@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",
  • In the same file enter your domain in the Mattermost configuration file under ServiceSettings Press Ctrl+W to search then save ctrl+s and close ctrl+x .
sudo nano /opt/mattermost/config/config.json

Sample

{
    "ServiceSettings": {
        "SiteURL": "chat.itnixpro.com",
        "WebsocketURL": "",
        "LicenseFileLocation": "",
        "ListenAddress": ":8065",
        "ConnectionSecurity": "",
        "TLSCertFile": "",
        "TLSKeyFile": "",
        "TLSMinVer": "1.2",
        "TLSStrictTransport": false,

Configure Systemd Service

  • Create Mattermost Systemd.
sudo nano /etc/systemd/system/mattermost.service
  • Copy the data below into the file and save it.
[Unit]

Description=Mattermost

After=network.target

After=postgresql.service

Requires=postgresql.service

[Service]

Type=notify

ExecStart=/opt/mattermost/bin/mattermost

TimeoutStartSec=3600

Restart=always

RestartSec=10

WorkingDirectory=/opt/mattermost

User=mattermost

Group=mattermost

LimitNOFILE=49152

[Install]

WantedBy=multi-user.target
  • Add the new unit in systemd using the following command.
sudo systemctl daemon-reload
  • Use the commands below to start and enable mattermost service.
sudo systemctl start mattermost.service
  • Set Mattermost to start automatically when the system turns on.
sudo systemctl enable mattermost.service
  • Verify its running.
systemctl status mattermost.service

Sample output

● mattermost.service - Mattermost
     Loaded: loaded (/etc/systemd/system/mattermost.s>
     Active: active (running) since Tue 2022-03-01 22>
   Main PID: 1466 (mattermost)
      Tasks: 49 (limit: 4588)
     Memory: 378.0M
     CGroup: /system.slice/mattermost.service
             ├─1466 /opt/mattermost/bin/mattermost
             ├─1989 plugins/com.mattermost.nps/server>
             ├─1990 plugins/com.mattermost.plugin-cha>
             ├─2003 plugins/playbooks/server/dist/plu>
             └─2011 plugins/focalboard/server/dist/pl>

Mar 01 22:05:52 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:53 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:53 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:53 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:53 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:53 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:55 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:55 chat.itnixpro.com mattermost[1466]: {>
Mar 01 22:05:55 chat.itnixpro.com systemd[1]: Started>
Mar 01 22:05:55 chat.itnixpro.com mattermost[1466]: {>
lines 1-23/23 (END)

Install Nginx on Ubuntu 22.04

  • Install Nginx by running the command below.
sudo apt -y install nginx
  • Create a new Mattermost configuration file.
sudo nano /etc/nginx/conf.d/mattermost.conf
  • Paste the configuration settings below.
upstream backend {
   server 127.0.0.1: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    chat.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://backend;
   }

   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://backend;
   }
}
  • Restart Nginx using the following commands.
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx

Access Mattermost Web Interface on Ubuntu 22.04

  • Fire up your favorite browser and navigate to your server IP followed by port 8065 e.g. server-IP:8065 or localhost:8065 as shown below. Enter details required to create your account.
  • You can create a team in the next page as shown below or proceed to system console.
  • I will create a team by entering team name.
  • In the next page I will leave team URL as default and click finish button to complete.
  • You will be taken to dashboard where you can complete your profile details.
  • To access system console in case you started by creating a team, click the dots on top left part. Then system console on the drop menu that will appear.
  • You will be taken to system console where you manage Mattermost settings.
  • You have reached the end of the article, Congratulations. You have learned how to Install Mattermost on Ubuntu 22.04.

Read more on Mattermost Documentation

Other Tutorials

Install PostgreSQL on Ubuntu 22.04

Install DBeaver on Ubuntu 22.04

Install pgAdmin on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment