Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Set Up Mattermost Linux Server

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, you can set up a Mattermost Linux server by installing the server software on a compatible Linux distribution, configuring a database, and accessing the web interface to complete setup. This guide walks you through installing Mattermost on a Debian or Ubuntu system using PostgreSQL and Nginx as a reverse proxy, which is the recommended production setup.

What You'll Need

  • A Linux server running Ubuntu 20.04, 22.04, or Debian 11/12
  • At least 2 GB RAM (4 GB recommended)
  • 2+ CPU cores
  • 10 GB+ free disk space
  • Root or sudo access
  • A domain name pointing to your server's public IP
  • Basic knowledge of Linux command line

Step-by-Step

  1. Connect to your Linux server via SSH using your preferred terminal or SSH client.
  2. Update the system packages:
    sudo apt update && sudo apt upgrade -y
  3. Install PostgreSQL database server:
    sudo apt install postgresql postgresql-contrib -y
  4. Switch to the PostgreSQL user and create a database and user for Mattermost:
    sudo -u postgres createuser --pwprompt mattermost
    sudo -u postgres createdb --owner=mattermost mattermost
    When prompted, set a strong password and remember it.
  5. Install additional dependencies:
    sudo apt install wget nginx git -y
  6. Download the latest Mattermost server package. Visit Mattermost Download Page to find the current Linux x64 .tar.gz link. Replace the URL below with the latest one if needed:
    cd /tmp
    wget https://releases.mattermost.com/7.8.1/mattermost-7.8.1-linux-amd64.tar.gz
  7. Extract the package to /opt/mattermost:
    sudo tar -xzf mattermost-*.tar.gz -C /opt
  8. Create a system user for Mattermost:
    sudo useradd --system --user-group mattermost
  9. Set ownership of the Mattermost directory:
    sudo chown -R mattermost:mattermost /opt/mattermost
    sudo chmod -R g+w /opt/mattermost
  10. Configure the database settings in the config file:
    sudo cp /opt/mattermost/config/config.json /opt/mattermost/config/config.json.bak
    sudo nano /opt/mattermost/config/config.json
    Find the "SqlSettings" section and update:
    "DriverName": "postgres",
    "DataSource": "postgres://mattermost:your_password@localhost:5432/mattermost?sslmode=disable",
    "DataSourceReplicas": [],
    "DataSourceSearchReplicas": []
    Save and exit (Ctrl+O, Enter, Ctrl+X).
  11. Create a systemd service file:
    sudo nano /etc/systemd/system/mattermost.service
    Add the following content:
    [Unit]
    Description=Mattermost
    After=postgresql.service
    Requires=postgresql.service
    
    [Service]\nType=notify
    User=mattermost
    Group=mattermost
    ExecStart=/opt/mattermost/bin/mattermost
    Restart=always
    RestartSec=10
    WorkingDirectory=/opt/mattermost
    ExecReload=/bin/kill -HUP $MAINPID
    LimitNOFILE=49152
    
    [Install]
    WantedBy=multi-user.target
    Save and exit.
  12. Reload systemd and enable the service:
    sudo systemctl daemon-reexec
    sudo systemctl enable mattermost
    sudo systemctl start mattermost
  13. Verify the service is running:
    sudo systemctl status mattermost
    You should see "active (running)".
  14. Configure Nginx as a reverse proxy. Create a server block:
    sudo nano /etc/nginx/sites-available/mattermost
    Add:
    server {
        listen 80;
        server_name your-domain.com;
    
        location / {
            proxy_pass http://localhost:8065;
            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 300s;
            proxy_cache_revalidate on;
        }
    }
    Replace your-domain.com with your actual domain.
  15. Enable the site:
    sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost
    sudo nginx -t
    sudo systemctl reload nginx
  16. Open a web browser and navigate to your domain. You should see the Mattermost setup page. Create your first team and system admin account.
  17. (Optional) Secure with HTTPS using Let's Encrypt:
    sudo apt install certbot python3-certbot-nginx -y
    sudo certbot --nginx -d your-domain.com
    Follow the prompts to install and auto-renew the certificate.

Common Mistakes

  • Using the default SQLite database in production — it's only for testing. Always use PostgreSQL or MySQL.
  • Forgetting to set correct file permissions — Mattermost must own its directory.
  • Not opening port 80/443 in the firewall — ensure UFW or iptables allows HTTP/HTTPS.
  • Typing the database password incorrectly in config.json — double-check the DataSource string.
  • Skipping Nginx configuration — direct exposure of port 8065 is not secure or production-ready.

Tips

  • Regularly back up the /opt/mattermost directory and PostgreSQL database.
  • Monitor logs using journalctl -u mattermost -f to catch issues early.
  • Use systemd to manage the service: sudo systemctl restart mattermost after config changes.
  • Set up automatic security updates on your Linux server.
  • Test email integration early using SMTP settings in the System Console.

Troubleshooting

If the Mattermost service fails to start, check the status with sudo systemctl status mattermost. Common issues include incorrect database credentials, missing dependencies, or port conflicts. If Nginx shows a 502 error, verify Mattermost is running and listening on port 8065 (sudo netstat -tuln | grep 8065). If the web page doesn't load, ensure your domain DNS points to the server and the firewall allows traffic. If you get a blank page, clear your browser cache or try incognito mode. For database connection errors, confirm PostgreSQL is running (sudo systemctl status postgresql) and the user has correct privileges. If Let's Encrypt fails, ensure port 80 is accessible and the domain resolves publicly.

Frequently Asked Questions

Can I use MySQL instead of PostgreSQL?

Yes, Mattermost supports both. Change the DriverName to "mysql" and adjust the DataSource string accordingly.

How do I update Mattermost?

Download the new .tar.gz, stop the service, back up config.json, extract over /opt/mattermost, then restart.

Is it safe to expose port 8065 directly?

No. Always use a reverse proxy like Nginx with HTTPS to secure traffic and hide the backend port.

How do I back up my Mattermost data?

Back up the /opt/mattermost directory and run a PostgreSQL dump: sudo -u postgres pg_dump mattermost > backup.sql.

Can I run Mattermost on a Raspberry Pi?

Yes, but only for small teams. Use the ARM64 build and ensure sufficient RAM and swap space.

How do I enable email notifications?

Go to System Console > Notifications > Email and enter your SMTP settings.