How to Deploy Mattermost on Ubuntu 24.04
Learn how to deploy Mattermost on Ubuntu 24.04 LTS with PostgreSQL, Nginx reverse proxy, systemd daemon, and automated Let's Encrypt SSL encryption.

6 min read
Learn how to deploy Mattermost on Ubuntu 24.04 LTS with PostgreSQL, Nginx reverse proxy, systemd daemon, and automated Let's Encrypt SSL encryption.
- Prerequisites and Supported Releases
- Step 1: Updating System Packages and Installing PostgreSQL
- Step 2: Creating Dedicated Database and User for Mattermost
Interactive Builder for this Guide
Build your custom nginx syntax (How to Deploy Mattermost on Ubuntu 24.04)
server {
listen 80;
listen [::]:80;
server_name app.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name app.example.com;
ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
gzip on;
gzip_types text/plain text/css application/json application/javascript application/xml;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}server_nameBinds this virtual host to app.example.comreturn 301 https://...Redirects all plain HTTP requests permanently to TLS/HTTPSproxy_pass http://127.0.0.1:3000Forwards HTTP + WebSocket requests to local application serverX-Content-Type-Options / X-Frame-OptionsProtects users against MIME sniffing and clickjackingMattermost is an enterprise-grade, open-source secure collaboration and communication platform designed as a private, high-trust alternative to Slack and Microsoft Teams. Built for technical and security-sensitive organizations, Mattermost provides real-time channel-based messaging, voice and screen sharing, workflow automation (Playbooks), audio/video calling, and deep integration with developer toolchains like GitHub, GitLab, and Jira.
By self-hosting Mattermost on Ubuntu, organizations maintain 100% data ownership, full compliance with strict regulatory frameworks (GDPR, HIPAA, and SOC 2), and freedom from third-party vendor lock-in. Understanding how to deploy mattermost on ubuntu 24.04 gives security-conscious organizations a private, self-hosted Slack alternative featuring end-to-end auditability, channels, voice calling, and workflow automation.
In this step-by-step tutorial, we demonstrate how to deploy Mattermost on Ubuntu 24.04 LTS (Noble Numbat). We cover installing and securing PostgreSQL, provisioning a dedicated database and user, downloading and extracting the Mattermost server binary into /opt/mattermost, configuring storage directories and file permissions, establishing an Nginx reverse proxy with WebSocket support, and securing the deployment with Let's Encrypt SSL.
Deploy and configure a production-ready Mattermost collaboration and messaging platform on Ubuntu 24.04 LTS with PostgreSQL database, Nginx reverse proxy, and SSL.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A cloud server, VPS, or dedicated instance running
Ubuntu 24.04 LTS. - A non-root user account configured with administrative
sudoprivileges. - A registered domain name (e.g.,
mattermost.example.com) pointed to your server IP address. - At least
2 GB of RAM(4 GB to 8 GB recommended for enterprise teams and extensive search indexing).
Step 1: Updating System Packages and Installing PostgreSQL
Mattermost requires a robust relational database engine to store messages, channel memberships, user profiles, and audit records. PostgreSQL is the officially supported and recommended database for Mattermost.
First, refresh your local APT repository index and upgrade installed packages.
Install PostgreSQL along with the postgresql-contrib package using APT.
Enable and start the PostgreSQL service daemon, and verify its active status.
# Update APT package repositories
sudo apt update && sudo apt upgrade -y
# Install PostgreSQL database server
sudo apt install -y postgresql postgresql-contrib curl wget tar
# Enable and verify PostgreSQL service
sudo systemctl enable --now postgresql
sudo systemctl status postgresql --no-pager
Step 2: Creating Dedicated Database and User for Mattermost
Log into the PostgreSQL administrative shell as the postgres user.
Create a dedicated database user named mmuser with a strong, randomized password.
Create the database named mattermost owned by mmuser with UTF8 encoding.
Grant all privileges on the database to mmuser and exit the PostgreSQL prompt.
# Open PostgreSQL administrative shell
sudo -u postgres psql
# Execute database provisioning commands:
CREATE USER mmuser WITH PASSWORD 'StrongMattermostPass123!';
CREATE DATABASE mattermost OWNER mmuser ENCODING 'UTF8';
GRANT ALL PRIVILEGES ON DATABASE mattermost TO mmuser;
\q
Step 3: Downloading and Extracting Mattermost Server Binary
Download the latest stable release tarball of Mattermost Server directly from the official Mattermost download repository.
Extract the archive into the /opt/ system directory.
Create a dedicated directory at /opt/mattermost/data for storing user file uploads, avatars, and attachments.
Assign ownership of the entire directory tree to the mattermost user.
# Download latest stable Mattermost binary archive
cd /tmp
wget https://releases.mattermost.com/9.11.1/mattermost-9.11.1-linux-amd64.tar.gz -O mattermost.tar.gz
# Extract archive into /opt/
sudo tar -xzf mattermost.tar.gz -C /opt/
# Create data directory for uploads
sudo mkdir -p /opt/mattermost/data
# Clean up downloaded archive
rm -f /tmp/mattermost.tar.gz
Step 4: Creating Dedicated Mattermost System User and Permissions
For security best practices, never run Mattermost under the root user account.
Create an unprivileged system user and group named mattermost without interactive login privileges.
Assign ownership of /opt/mattermost to the mattermost user.
Grant the mattermost binary permission to bind to low-privileged network ports if required using setcap.
# Create dedicated system user and group
sudo useradd --system --user-group --shell /sbin/nologin mattermost
# Set directory ownership and write permissions
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost
# Grant capability to bind to privileged ports (optional)
sudo setcap cap_net_bind_service=+ep /opt/mattermost/bin/mattermost
Step 5: Configuring Database Connection in config.json
Configure Mattermost's database connection settings in the master configuration file located at /opt/mattermost/config/config.json.
Open the file with administrative privileges.
Locate the SqlSettings section: set "DriverName": "postgres", and configure the "DataSource" connection string with your PostgreSQL user, password, and database name.
Ensure "SiteURL" is configured to your public HTTPS domain (e.g., https://mattermost.example.com).
Furthermore, ensure that connection pool parameters like MaxOpenConns and MaxIdleConns are properly set to support concurrent team messaging throughput without exhausting database connections.
# Configure PostgreSQL connection in /opt/mattermost/config/config.json
sudo sed -i 's|"DriverName": "mysql"|"DriverName": "postgres"|' /opt/mattermost/config/config.json
sudo sed -i 's|"DataSource": ".*"|"DataSource": "postgres://mmuser:[email protected]:5432/mattermost?sslmode=disable\&connect_timeout=10"|' /opt/mattermost/config/config.json
sudo sed -i 's|"SiteURL": ".*"|"SiteURL": "https://mattermost.example.com"|' /opt/mattermost/config/config.json
Step 6: Creating the Systemd Service Unit for Mattermost
Configure a systemd service unit file so that Mattermost runs as a background service that automatically launches at boot and recovers from unexpected process terminations.
Create the unit file at /etc/systemd/system/mattermost.service.
Reload systemd daemon, start Mattermost, and confirm the service reports an active status.
# Create systemd service unit file
sudo bash -c 'cat <<EOF > /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost Enterprise Messaging Service
After=network.target postgresql.service
Requires=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
EOF'
# Reload systemd, enable and launch Mattermost
sudo systemctl daemon-reload
sudo systemctl enable --now mattermost
sudo systemctl status mattermost --no-pager
Step 7: Configuring Nginx Reverse Proxy with WebSockets
Mattermost communicates over HTTP and WebSockets (port 8065). To provide TLS termination, HTTP/2 performance, and port 80/443 mapping, configure Nginx as a reverse proxy.
Install Nginx using APT.
Create a server block configuration file at /etc/nginx/sites-available/mattermost.conf.
Configure the required Upgrade and Connection HTTP headers for real-time WebSocket messaging, enable the site, and reload Nginx.
# Install Nginx
sudo apt install -y nginx
# Create Nginx virtual host configuration
sudo bash -c 'cat <<EOF > /etc/nginx/sites-available/mattermost.conf
upstream mattermost {
server 127.0.0.1:8065;
keepalive 32;
}
server {
listen 80;
server_name mattermost.example.com;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_pass http://mattermost;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$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;
}
location / {
proxy_pass http://mattermost;
proxy_set_header Host \$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;
}
}
EOF'
# Enable site and reload Nginx
sudo ln -sf /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 8: Securing with Let's Encrypt SSL and Completing Web Setup
Secure your Mattermost domain with a free Let's Encrypt SSL certificate using Certbot.
Certbot automatically adjusts Nginx configuration parameters and sets up automatic 90-day certificate renewals.
Open your web browser and navigate to https://mattermost.example.com.
The initial screen prompts you to create your primary System Administrator account (Email, Username, and Password).
Provide an organization name, invite team members, and begin collaborating securely.
# Install Certbot and Nginx plugin
sudo apt install -y certbot python3-certbot-nginx
# Obtain and apply SSL certificate
sudo certbot --nginx -d mattermost.example.com --non-interactive --agree-tos -m [email protected] --redirect
# Initial Setup URL: https://mattermost.example.com
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
Mattermost service fails to start: 'Failed to ping DB: dial tcp 127.0.0.1:5432: connect: connection refused'
Resolution: Ensure PostgreSQL is active: sudo systemctl status postgresql. Verify that PostgreSQL is listening on port 5432 and the credentials in /opt/mattermost/config/config.json match the credentials granted in Step 2.
WebSocket connection failed or messages do not update in real-time
Resolution: Verify that your Nginx configuration contains the location ~ /api/v[0-9]+/(users/)?websocket$ block with Upgrade and Connection "upgrade" headers.
Browser warning: 'Site URL in config.json does not match access URL'
Resolution: Open /opt/mattermost/config/config.json and ensure "SiteURL" is set exactly to your public HTTPS domain (including https:// and no trailing slash), then restart the service.
Security Best Practices and Hardening
Never run the Mattermost daemon under the root user account; use the dedicated unprivileged 'mattermost' system user.
Enable Multi-Factor Authentication (MFA) for all administrative accounts in System Console > Authentication > MFA.
Restrict database access in pg_hba.conf strictly to localhost (127.0.0.1) using md5 or scram-sha-256 password hashing.
Perform automated nightly backups of the PostgreSQL database using pg_dump and backup the /opt/mattermost/data directory.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
https://mattermost.example.com) to log in.sudo systemctl stop mattermost, backup your database, extract the new tarball over /opt/mattermost (preserving config/config.json and data/), and restart the service.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides


Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!