Mattermost is an open-source, self-hosted messaging platform built as an alternative to Slack and Microsoft Teams. It gives you full control over your data, supports real-time chat, file sharing, integrations, and works well for DevOps teams that need a private communication hub with webhook and bot support.
This guide walks through installing Mattermost 11.5 on Ubuntu 24.04 LTS with PostgreSQL as the database backend, Nginx as a reverse proxy, and Let’s Encrypt SSL for HTTPS. Every command has been written for Ubuntu 24.04 but also works on Ubuntu 22.04 with no changes.
Prerequisites
Before starting, make sure you have the following in place:
- A server running Ubuntu 24.04 LTS with at least 2 GB RAM and 2 CPU cores
- Root or sudo access to the server
- A domain name (e.g. mattermost.example.com) pointed to your server’s public IP
- Ports 80, 443, and 8065 available (8065 is Mattermost’s default port)
- A working internet connection for downloading packages
Step 1: Install PostgreSQL on Ubuntu 24.04
Mattermost supports PostgreSQL as its primary database. Ubuntu 24.04 ships with PostgreSQL 16 in the default repositories, which works perfectly. Install it with the following command:
sudo apt update
sudo apt install -y postgresql postgresql-contrib
Once installed, PostgreSQL starts automatically. Confirm the service is running:
sudo systemctl status postgresql
The output should show the service as active and enabled:
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
Active: active (exited) since Sat 2026-03-22 10:00:00 UTC; 5s ago
For a more detailed PostgreSQL setup including remote access and tuning, see our guide on installing and configuring PostgreSQL on Ubuntu.
Step 2: Create a Database and User for Mattermost
Mattermost needs its own PostgreSQL database and a dedicated user. Switch to the postgres system user and open the PostgreSQL shell:
sudo -u postgres psql
Run the following SQL commands to create the database, user, and assign permissions. Replace StrongPassword123 with your own secure password:
CREATE USER mmuser WITH PASSWORD 'StrongPassword123';
CREATE DATABASE mattermost WITH OWNER mmuser TEMPLATE template0 ENCODING 'UTF8';
GRANT ALL PRIVILEGES ON DATABASE mattermost TO mmuser;
\q
Verify the database was created by listing all databases:
sudo -u postgres psql -c "\l" | grep mattermost
You should see the mattermost database in the list with mmuser as the owner:
mattermost | mmuser | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
Step 3: Download and Install Mattermost Server
Download the latest Mattermost Server release (v11.5.1 at the time of writing) and extract it to /opt:
wget https://releases.mattermost.com/11.5.1/mattermost-11.5.1-linux-amd64.tar.gz
Extract the archive and move it to /opt/mattermost:
tar -xzf mattermost-11.5.1-linux-amd64.tar.gz
sudo mv mattermost /opt/
Create the data directory where Mattermost stores uploaded files and other data:
sudo mkdir -p /opt/mattermost/data
Create a dedicated system user for Mattermost and set correct ownership:
sudo useradd --system --user-group mattermost
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost
Step 4: Configure Mattermost Database and Site URL
The main configuration file is located at /opt/mattermost/config/config.json. Open it in your editor:
sudo vi /opt/mattermost/config/config.json
Find the SqlSettings section and update the DriverName and DataSource values. Replace the default MySQL driver with PostgreSQL and set the connection string to match the database credentials you created in Step 2:
"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser:StrongPassword123@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",
"MaxIdleConns": 20,
"MaxOpenConns": 300,
"Trace": false,
"AtRestEncryptKey": "",
"QueryTimeout": 30
}
Next, find the ServiceSettings section and set the SiteURL to your domain name. Also confirm ListenAddress is set to port 8065:
"ServiceSettings": {
"SiteURL": "https://mattermost.example.com",
"ListenAddress": ":8065",
"ConnectionSecurity": "",
"TLSCertFile": "",
"TLSKeyFile": ""
}
Leave ConnectionSecurity empty since Nginx will handle SSL termination. Save and close the file.
Step 5: Create a Systemd Service for Mattermost
A systemd unit file lets Mattermost start automatically on boot and makes it easy to manage with systemctl. Create the service file:
sudo vi /etc/systemd/system/mattermost.service
Add the following configuration:
[Unit]
Description=Mattermost
After=syslog.target network.target postgresql.service
[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
LimitNOFILE=49152
Restart=always
RestartSec=10
WatchdogSec=60
[Install]
WantedBy=multi-user.target
Reload systemd, enable the service to start at boot, and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now mattermost
Check that Mattermost started successfully:
sudo systemctl status mattermost
The service should show active (running) with Mattermost listening on port 8065:
● mattermost.service - Mattermost
Loaded: loaded (/etc/systemd/system/mattermost.service; enabled; preset: enabled)
Active: active (running) since Sat 2026-03-22 10:05:00 UTC; 5s ago
Main PID: 12345 (mattermost)
Status: "OK"
Tasks: 45 (limit: 4557)
Memory: 150.0M
CPU: 3.500s
CGroup: /system.slice/mattermost.service
└─12345 /opt/mattermost/bin/mattermost
Confirm the port is open and listening:
ss -tlnp | grep 8065
You should see Mattermost bound to port 8065:
LISTEN 0 4096 *:8065 *:* users:(("mattermost",pid=12345,fd=18))
Step 6: Configure Nginx as a Reverse Proxy for Mattermost
Nginx sits in front of Mattermost to handle SSL, HTTP/2, and WebSocket connections. Install Nginx if it is not already present:
sudo apt install -y nginx
Create a new Nginx server block for Mattermost:
sudo vi /etc/nginx/sites-available/mattermost.conf
Add the following configuration. Replace mattermost.example.com with your actual domain name:
upstream mattermost_backend {
server 127.0.0.1:8065;
keepalive 32;
}
server {
listen 80;
server_name mattermost.example.com;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_max_body_size 50M;
proxy_read_timeout 600s;
proxy_pass http://mattermost_backend;
}
location / {
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_max_body_size 50M;
proxy_read_timeout 600s;
proxy_pass http://mattermost_backend;
}
}
The WebSocket location block is critical – Mattermost uses WebSockets for real-time messaging, and without the Upgrade and Connection headers, live updates will not work. If you are new to Nginx reverse proxy setups, our guide on installing Nginx on Ubuntu covers the basics.
Enable the site and remove the default Nginx configuration:
sudo ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
Test the Nginx configuration for syntax errors:
sudo nginx -t
If the test passes, you should see the following confirmation:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart Nginx and enable it to start at boot:
sudo systemctl restart nginx
sudo systemctl enable nginx
Step 7: Configure SSL with Let’s Encrypt
Secure your Mattermost instance with a free SSL certificate from Let’s Encrypt using Certbot. Install Certbot and the Nginx plugin:
sudo apt install -y certbot python3-certbot-nginx
Run Certbot to obtain and install the certificate. Replace the domain and email with your actual values:
sudo certbot --nginx -d mattermost.example.com --non-interactive --agree-tos -m [email protected]
Certbot automatically modifies the Nginx configuration to add SSL directives and sets up a redirect from HTTP to HTTPS. Verify the certificate is installed correctly:
sudo certbot certificates
The output shows the certificate details including the expiry date:
Certificate Name: mattermost.example.com
Domains: mattermost.example.com
Expiry Date: 2026-06-20 09:00:00+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/mattermost.example.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/mattermost.example.com/privkey.pem
Certbot installs a systemd timer that automatically renews certificates before they expire. Confirm the renewal timer is active:
sudo systemctl status certbot.timer
Step 8: Configure UFW Firewall
Ubuntu 24.04 uses UFW (Uncomplicated Firewall) by default. Open the necessary ports for HTTP, HTTPS, and SSH access:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
The Nginx Full profile opens both port 80 (HTTP) and port 443 (HTTPS). You do not need to open port 8065 externally since Nginx proxies traffic to Mattermost internally. Verify the firewall rules:
sudo ufw status
The output confirms the allowed ports:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
Step 9: Access Mattermost Web UI and Create a Team
Open your browser and navigate to your Mattermost domain:
https://mattermost.example.com
The first user to access the Mattermost instance becomes the System Administrator. You will see a signup form where you fill in your email, username, and password. After creating the admin account, Mattermost prompts you to create your first team.
Enter a team name and URL. Once the team is created, you land on the main messaging interface. From here you can:
- Create public and private channels for different topics
- Invite team members via email or a shareable invite link
- Configure integrations with tools like GitLab, Jenkins, and Jira from the System Console
- Set up incoming and outgoing webhooks for automation
To access the System Console for server-wide settings, click your profile icon in the top-left corner and select System Console. If you already use Rocket.Chat, Mattermost offers a migration tool to import channels and message history.
Step 10: Enable Push Notifications
Push notifications let team members receive alerts on their mobile devices when they get new messages. Mattermost provides a free hosted push notification service (HPNS) for self-hosted instances.
Open the System Console by clicking your profile icon and selecting System Console. Navigate to Environment – Push Notification Server. Set the following:
- Enable Push Notifications: Use HPNS connection with uptime SLA to receive notifications
- Push Notification Server:
https://push-test.mattermost.com(for testing) orhttps://push.mattermost.com(for production with a Mattermost license)
Click Save to apply the changes. Install the Mattermost mobile app from the official download page on your iOS or Android device. Log in with your server URL and credentials to start receiving push notifications.
For the test server (push-test.mattermost.com), you are limited to 1000 notifications per minute. Production deployments with an Enterprise license can use the full HPNS endpoint without limits.
Conclusion
You now have a working Mattermost 11.5 instance running on Ubuntu 24.04 with PostgreSQL, behind Nginx with SSL encryption. The setup includes a systemd service for automatic restarts, WebSocket support for real-time messaging, and push notifications for mobile users.
For production use, consider setting up automated PostgreSQL backups and replication for high availability, monitoring Mattermost with Prometheus metrics (available at the /metrics endpoint), and restricting team creation to admins only in the System Console.