How to Install Mattermost on Ubuntu 20.04/22.04 with AvaHost

Mattermost is a secure, open-source messaging platform, a self-hosted alternative to Slack, ideal for privacy-focused teams. This guide simplifies installing Mattermost on an AvaHost Ubuntu 20.04/22.04 VPS or dedicated server, with practical examples and tips for a scalable, secure setup.

Introduction

Mattermost offers robust collaboration tools with full data control, perfect for organizations needing privacy and scalability. With AvaHost’s high-performance VPS and NVMe storage, you can deploy a reliable Mattermost instance for real-time team communication.

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

Installing Mattermost on an AvaHost Ubuntu 20.04/22.04 VPS provides a secure, scalable messaging platform for team collaboration. The steps above, with examples like PostgreSQL setup and Nginx configuration, ensure a smooth deployment. Paired with AvaHost’s reliable infrastructure and free SSL, your Mattermost instance will support privacy-focused, high-performance communication. Regularly update and back up your system to maintain security and reliability as your team grows.