How to Install Mattermost on Ubuntu 24.04

Estimated reading: 6 minutes 67 views

1. Overview & System Requirements

This practical guide provides step-by-step instructions to install and configure How to Install Mattermost on Ubuntu 24.04. Every single command has been executed and validated in a standardized sandbox environment, ensuring zero version conflicts and verified system health.

Operating System Ubuntu 24.04 LTS (Noble Numbat) / Ubuntu 22.04 LTS
Minimum Hardware 2 vCPU, 4GB RAM, 20GB Free Storage
Database Backend PostgreSQL 14+ (PostgreSQL 16 recommended)
Access Privileges Root or sudo-enabled user

2. Step-by-Step Installation & Verification

Step 1: Install prerequisites and dependencies

Execute the following command in terminal:

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget jq postgresql postgresql-contrib nginx sudo ca-certificates ufw

 

Step 2: Configure firewall rules for HTTP and Mattermost

Execute the following command in terminal:

ufw allow 80/tcp && ufw allow 8065/tcp

 

Step 3: Start PostgreSQL service

Execute the following command in terminal:

service postgresql start && service postgresql status

 

Step 4: Provision PostgreSQL database and user

Execute the following command in terminal:

su - postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='mmuser'\" | grep -q 1 || psql -c \"CREATE USER mmuser WITH PASSWORD 'mmuser_secure_pass';\" && createdb -O mmuser mattermost 2>/dev/null || true"

 

Step 5: Verify PostgreSQL connection and database

Execute the following command in terminal:

PGPASSWORD='mmuser_secure_pass' psql -h 127.0.0.1 -U mmuser -d mattermost -c 'SELECT current_user, current_database();'

 

Step 6: Download and extract Mattermost Server binary

Execute the following command in terminal:

curl -fsSL https://releases.mattermost.com/9.11.3/mattermost-9.11.3-linux-amd64.tar.gz -o /tmp/mattermost.tar.gz && tar -xzf /tmp/mattermost.tar.gz -C /opt && rm -f /tmp/mattermost.tar.gz && ls -d /opt/mattermost

 

Step 7: Configure Mattermost user and file permissions

Execute the following command in terminal:

id -u mattermost >/dev/null 2>&1 || useradd --system --user-group mattermost && mkdir -p /opt/mattermost/data && chown -R mattermost:mattermost /opt/mattermost && chmod -R g+w /opt/mattermost

 

Step 8: Configure Mattermost database connection and local mode

Execute the following command in terminal:

jq '.SqlSettings.DriverName = "postgres" | .SqlSettings.DataSource = "postgres://mmuser:[email protected]:5432/mattermost?sslmode=disable&connect_timeout=10" | .ServiceSettings.SiteURL = "http://localhost" | .ServiceSettings.EnableLocalMode = true' /opt/mattermost/config/config.json > /tmp/config.json && cp /tmp/config.json /opt/mattermost/config/config.json && rm /tmp/config.json && chown mattermost:mattermost /opt/mattermost/config/config.json

 

Step 9: Inspect configured Mattermost database and service settings

Execute the following command in terminal:

jq '{DriverName: .SqlSettings.DriverName, DataSource: .SqlSettings.DataSource, SiteURL: .ServiceSettings.SiteURL, EnableLocalMode: .ServiceSettings.EnableLocalMode}' /opt/mattermost/config/config.json

 

Step 10: Configure Nginx reverse proxy for Mattermost

Execute the following command in terminal:

cat <<'EOF' > /etc/nginx/sites-available/mattermost
upstream backend {
    server 127.0.0.1:8065;
    keepalive 32;
}

server {
    listen 80 default_server;
    server_name _;

    location ~ /api/v[0-9]+/(users/)?websocket$ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 50M;
        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;
        proxy_pass http://backend;
    }

    location / {
        client_max_body_size 50M;
        proxy_set_header Connection "";
        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;
        proxy_pass http://backend;
    }
}
EOF
rm -f /etc/nginx/sites-enabled/default && ln -sf /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost

 

Step 11: Inspect Nginx reverse proxy configuration

Execute the following command in terminal:

cat /etc/nginx/sites-available/mattermost

 

Step 12: Test and restart Nginx service

Execute the following command in terminal:

nginx -t && service nginx restart

 

Step 13: Create Mattermost systemd service unit

Execute the following command in terminal:

cat <<'EOF' > /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost
After=network.target postgresql.service
Requires=postgresql.service

[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target
EOF

 

Step 14: Inspect Mattermost systemd service unit

Execute the following command in terminal:

cat /etc/systemd/system/mattermost.service

 

Step 15: Start Mattermost application service

Execute the following command in terminal:

if [ -d /run/systemd/system ]; then systemctl daemon-reload && systemctl enable --now mattermost; else su -s /bin/bash mattermost -c "cd /opt/mattermost && ./bin/mattermost --config /opt/mattermost/config/config.json > /opt/mattermost/mattermost.log 2>&1 &"; fi

 

Step 16: Verify Mattermost health endpoint

Execute the following command in terminal:

for i in $(seq 1 30); do if curl -fsS http://127.0.0.1:8065/api/v4/system/ping; then break; fi; sleep 2; done

 

Step 17: Provision initial System Administrator account via mmctl

Execute the following command in terminal:

/opt/mattermost/bin/mmctl --local user create --email [email protected] --username admin --password "MattermostAdmin2024!" --system-admin

 

Step 18: Create default DevOps team and assign admin

Execute the following command in terminal:

/opt/mattermost/bin/mmctl --local team create --name devops --display-name "DevOps Team" 2>/dev/null || true; /opt/mattermost/bin/mmctl --local team users add devops admin 2>/dev/null || true; /opt/mattermost/bin/mmctl --local team list

 

Step 19: Verify Mattermost proxy response through Nginx

Execute the following command in terminal:

curl -fsS http://127.0.0.1/api/v4/system/ping

 

Step 20: Log in to Mattermost as System Administrator

Open web browser and access the service URL: http://localhost:32780/login

Verified UI Actions:

  • Fill ‘admin’ into input[name=’loginId’]
  • Fill ‘MattermostAdmin2024!’ into input[name=’password’]
  • Click ‘button[type=’submit’]’

 

Step 21: Explore DevOps channels and Town Square

Open web browser and access the service URL: http://localhost:32780/devops/channels/town-square

Verified UI Actions:

 

Step 22: Navigate to System Console administration area

Open web browser and access the service URL: http://localhost:32780/admin_console

Verified UI Actions:

 

3. Security & Production Recommendations

PRODUCTION RECOMMENDATIONS: To ensure high security and stability in a production environment:
1. Configure Nginx or Caddy as a Reverse Proxy with automated SSL/TLS via Let’s Encrypt.
2. Set up UFW firewall to strictly allow only ports 80, 443, and your customized SSH port.
3. Configure automated daily backups for the PostgreSQL database and uploaded server assets.

 

Share this Doc

How to Install Mattermost on Ubuntu 24.04

Or copy link

CONTENTS