Set Up Mattermost Linux Server
In this article
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
- Connect to your Linux server via SSH using your preferred terminal or SSH client.
- Update the system packages:
sudo apt update && sudo apt upgrade -y - Install PostgreSQL database server:
sudo apt install postgresql postgresql-contrib -y - Switch to the PostgreSQL user and create a database and user for Mattermost:
When prompted, set a strong password and remember it.sudo -u postgres createuser --pwprompt mattermost sudo -u postgres createdb --owner=mattermost mattermost - Install additional dependencies:
sudo apt install wget nginx git -y - 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 - Extract the package to /opt/mattermost:
sudo tar -xzf mattermost-*.tar.gz -C /opt - Create a system user for Mattermost:
sudo useradd --system --user-group mattermost - Set ownership of the Mattermost directory:
sudo chown -R mattermost:mattermost /opt/mattermost sudo chmod -R g+w /opt/mattermost - Configure the database settings in the config file:
Find the "SqlSettings" section and update:sudo cp /opt/mattermost/config/config.json /opt/mattermost/config/config.json.bak sudo nano /opt/mattermost/config/config.json
Save and exit (Ctrl+O, Enter, Ctrl+X)."DriverName": "postgres", "DataSource": "postgres://mattermost:your_password@localhost:5432/mattermost?sslmode=disable", "DataSourceReplicas": [], "DataSourceSearchReplicas": [] - Create a systemd service file:
Add the following content:sudo nano /etc/systemd/system/mattermost.service
Save and exit.[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 - Reload systemd and enable the service:
sudo systemctl daemon-reexec sudo systemctl enable mattermost sudo systemctl start mattermost - Verify the service is running:
You should see "active (running)".sudo systemctl status mattermost - Configure Nginx as a reverse proxy. Create a server block:
Add:sudo nano /etc/nginx/sites-available/mattermost
Replaceserver { 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; } }your-domain.comwith your actual domain. - Enable the site:
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost sudo nginx -t sudo systemctl reload nginx - Open a web browser and navigate to your domain. You should see the Mattermost setup page. Create your first team and system admin account.
- (Optional) Secure with HTTPS using Let's Encrypt:
Follow the prompts to install and auto-renew the certificate.sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx -d your-domain.com
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/mattermostdirectory and PostgreSQL database. - Monitor logs using
journalctl -u mattermost -fto catch issues early. - Use systemd to manage the service:
sudo systemctl restart mattermostafter 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.