How to Install Mattermost on Ubuntu 24.04
Mattermost is an open-source team collaboration platform that provides secure messaging, file sharing, and project management features. This guide will walk you through installing Mattermost on Ubuntu 24.04.
Prerequisites
- Ubuntu 24.04 server
- Root privileges or sudo access
- Minimum 2GB RAM
- Domain name pointing to your server
Step 1: Update System Packages
sudo apt update
sudo apt upgrade -y
Step 2: Install PostgreSQL Database
sudo apt install postgresql postgresql-contrib -y
Create a new database and user for Mattermost:
sudo -u postgres psql
Execute these PostgreSQL commands:
CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'your-password-here';
GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
\q
Step 3: Download and Install Mattermost
Create a system user for Mattermost:
sudo useradd --system --user-group mattermost
Download and extract Mattermost:
wget https://releases.mattermost.com/7.8.6/mattermost-7.8.6-linux-amd64.tar.gz
sudo tar -xvf mattermost*.tar.gz -C /opt
Create the data directory and set permissions:
sudo mkdir /opt/mattermost/data
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost
Step 4: Configure Mattermost
Copy and edit the configuration file:
cd /opt/mattermost/config
sudo cp config.json config.json.original
sudo nano config.json
Update these settings in the configuration:
{
"ServiceSettings": {
"SiteURL": "https://your-domain.com"
},
"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser:your-password-here@localhost:5432/mattermost?sslmode=disable"
}
}
Step 5: Create Systemd Service
sudo nano /etc/systemd/system/mattermost.service
Add this service configuration:
[Unit]
Description=Mattermost
After=network.target postgresql.service
[Service]
Type=notify
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target
Step 6: Install and Configure Nginx
sudo apt install nginx -y
Create Nginx configuration for Mattermost:
sudo nano /etc/nginx/sites-available/mattermost
upstream backend {
server localhost:8065;
}
server {
listen 80;
server_name your-domain.com;
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_read_timeout 600s;
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_read_timeout 600s;
proxy_pass http://backend;
}
}
Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
Step 7: Secure with SSL Certificate
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Obtain SSL certificate:
sudo certbot --nginx -d your-domain.com
Step 8: Start Mattermost
sudo systemctl daemon-reload
sudo systemctl start mattermost
sudo systemctl enable mattermost
Verify the service status:
sudo systemctl status mattermost
Step 9: Initial Setup
Access your Mattermost installation at https://your-domain.com and create the first admin account.
Troubleshooting
Database Connection Issues
sudo -u mattermost psql -h localhost -U mmuser mattermost
sudo journalctl -u mattermost.service
Nginx Configuration
sudo nginx -t
sudo tail -f /var/log/nginx/error.log
Security Recommendations
- Enable rate limiting in Nginx
- Configure firewall rules
- Regularly update Mattermost and system packages
- Set up automated backups
Maintenance
Regular backup command:
sudo -u postgres pg_dump mattermost > mattermost_backup.sql
sudo tar -czf mattermost_data_backup.tar.gz /opt/mattermost/data/
Check for updates:
sudo systemctl stop mattermost
# Download and install new version
sudo systemctl start mattermost
Conclusion
Your Mattermost installation is now complete and secured with SSL. Remember to:
- Regularly backup your data
- Monitor system resources
- Keep the system updated
- Review security settings periodically