Platform
Mattermost Self-Hosted Team Chat on Linux with PostgreSQL
- Author :Liam K.
- Date :August 3, 2026
- Time :18 minutes
Mattermost is a self-hosted collaboration suite that replaces Slack for teams that need data control. The Team Edition covers channels, DMs, file sharing, and integrations. This guide installs Mattermost with PostgreSQL and HTTPS so you can run private ops chat on your own infrastructure.
Prerequisites
- Ubuntu 22.04+ with 2+ CPU and 4 GB RAM
- DNS for
chat.example.com - SMTP credentials for invites and notifications
Step 1: PostgreSQL Database
bash
sudo apt update
sudo apt install -y postgresql postgresql-contrib
sudo -u postgres psql <<'EOF'
CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'change-me-strong';
GRANT ALL PRIVILEGES ON DATABASE mattermost TO mmuser;
\c mattermost
GRANT ALL ON SCHEMA public TO mmuser;
[...]Command truncated. Copy to view full command.
Step 2: Install Mattermost
bash
MM_VERSION=10.2.0
sudo useradd --system --user-group mattermost
cd /opt
sudo wget https://releases.mattermost.com/${MM_VERSION}/mattermost-${MM_VERSION}-linux-amd64.tar.gz
sudo tar -xzf mattermost-${MM_VERSION}-linux-amd64.tar.gz
sudo mkdir -p /opt/mattermost/data
sudo chown -R mattermost:mattermost /opt/mattermostStep 3: Configure config.json
bash
sudo -u mattermost tee /opt/mattermost/config/config.json >/dev/null <<'EOF'
{
"ServiceSettings": {
"SiteURL": "https://chat.example.com",
"ListenAddress": "127.0.0.1:8065"
},
"SqlSettings": {
"DriverName": "postgres",
[...]Command truncated. Copy to view full command.
Step 4: systemd Service
bash
sudo tee /etc/systemd/system/mattermost.service >/dev/null <<'EOF'
[Unit]
Description=Mattermost
After=network.target postgresql.service
[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
Restart=always
[...]Command truncated. Copy to view full command.
Step 5: Nginx TLS Proxy
bash
sudo tee /etc/nginx/sites-available/mattermost >/dev/null <<'EOF'
upstream backend {
server 127.0.0.1:8065;
keepalive 32;
}
server {
listen 80;
server_name chat.example.com;
[...]Command truncated. Copy to view full command.
Step 6: Backup Database and Files
bash
sudo -u postgres pg_dump mattermost | gzip > /var/backups/mattermost-db-$(date +%F).sql.gz
sudo tar -czf /var/backups/mattermost-data-$(date +%F).tar.gz -C /opt/mattermost data configProduction Checklist
- Configure SMTP before inviting the whole team.
- Enable MFA for System Admin accounts.
- Keep database and
./databackups paired. - Monitor disk for uploaded files and attachment growth.
- Test WebSocket connectivity through the reverse proxy after TLS changes.
"Team chat is production infrastructure when incident response depends on it — back it up and watch it like any other critical service."
Technical Author

Liam K.
System administrator and technical writer specializing in server infrastructure, security and deployment. Creating comprehensive guides to help you master server administration.