Mattermost is a powerful open-source messaging platform designed as a self-hosted alternative to Slack and Microsoft Teams. It provides full data control, robust collaboration tools, and is ideal for organizations focused on privacy and scalability. This guide covers the full installation of Mattermost on an Ubuntu 20.04/22.04 server.

Prerequisites

Before starting, make sure you have:

  • A VPS or dedicated server running Ubuntu 20.04 or 22.04
  • Root privileges or sudo access
  • A domain name (optional but recommended)
  • Installed packages: PostgreSQL, NGINX, curl, wget, and unzip

Step 1: Install PostgreSQL

Mattermost requires PostgreSQL for data storage.

sudo apt update
sudo apt install postgresql postgresql-contrib -y

Create the database and user for Mattermost:

sudo -u postgres psql

Inside the PostgreSQL shell:

CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'strongpassword';
GRANT ALL PRIVILEGES ON DATABASE mattermost TO mmuser;
\q

Step 2: Download and Install Mattermost

Navigate to the /opt directory:

cd /opt

Download the latest version of Mattermost:

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

Replace X.X.X with the latest version number, e.g., 9.5.2.

Extract the archive:

tar -xvzf mattermost-*.tar.gz
sudo mv mattermost /opt
sudo mkdir /opt/mattermost/data

Step 3: Configure Mattermost

Open the configuration file:

sudo nano /opt/mattermost/config/config.json

Locate the database settings and update the connection string:

"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser:strongpassword@localhost:5432/mattermost?sslmode=disable",

Save and exit.

Step 4: Create System User and Systemd Service

Create a dedicated system user:

sudo useradd --system --user-group mattermost
sudo chown -R mattermost:mattermost /opt/mattermost

Create a systemd unit file:

sudo nano /lib/systemd/system/mattermost.service

Insert the following content:

[Unit]
Description=Mattermost
After=network.target>[Service]
Type=simple
User=mattermost
Group=mattermost
WorkingDirectory=/opt/mattermost
ExecStart=/opt/mattermost/bin/mattermost
Restart=always
LimitNOFILE=49152[Install]</code
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable mattermost
sudo systemctl start mattermost

Step 5: Install and Configure NGINX

sudo apt install nginx -y

Create a new site configuration file:

sudo nano /etc/nginx/sites-available/mattermost

Example configuration:

server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8065;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header X-Real-IP $remote_addr;
}
}

<

Enable the site and restart NGINX:

sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx

(Optional) Use Certbot to add HTTPS via Let’s Encrypt:

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com

Final Step: Access the Web Interface

Visit http://yourdomain.com in your browser. You’ll be prompted to create the first admin account and set up your team workspace.

Conclusion

You now have Mattermost installed and running on Ubuntu. With PostgreSQL handling data and NGINX managing web traffic, this setup is optimized for secure and scalable real-time collaboration. Make sure to regularly update the application and secure your system as you scale your teams and usage.