How to Install Mattermost on Ubuntu
Mattermost is an open-source messaging platform designed for team collaboration and communication. It provides a secure and self-hosted alternative to tools like Slack. This guide will walk you through the installation process of Mattermost on an Ubuntu server.
1. Prerequisites
Before you begin, ensure that you have the following:
- A server running Ubuntu 18.04 or later.
- Sudo privileges on the server.
- A domain name pointing to your server (optional but recommended for production).
2. Update Your System
Start by updating your system’s package index:
sudo apt update sudo apt upgrade -y
3. Install Required Dependencies
Mattermost requires certain software packages to function properly. Install them using the following command:
sudo apt install -y postgresql postgresql-contrib sudo apt install -y nginx sudo apt install -y certbot python3-certbot-nginx
4. Install Mattermost
Step 1: Download Mattermost
Go to the Mattermost downloads page and get the latest version of Mattermost. You can use wget to download it directly to your server:
wget https://releases.mattermost.com/7.5.0/mattermost-team-7.5.0-linux-amd64.tar.gz
(Note: Replace 7.5.0 with the latest version available.)
Step 2: Extract the Downloaded File
Extract the downloaded file:
tar -xvzf mattermost-team-7.5.0-linux-amd64.tar.gz
Step 3: Move Mattermost to the Desired Directory
Move the extracted folder to the /opt directory:
sudo mv mattermost /opt
Step 4: Create a Mattermost User
Create a dedicated user to run Mattermost:
sudo useradd -r -m mattermost
Set the ownership of the Mattermost directory:
sudo chown -R mattermost:mattermost /opt/mattermost
5. Set Up PostgreSQL Database
Step 1: Switch to the PostgreSQL User
sudo -i -u postgres
Step 2: Create a Database and User for Mattermost
Run the following commands in the PostgreSQL shell:
CREATE DATABASE mattermost_db; CREATE USER mattermost WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE mattermost_db TO mattermost;
Replace ‘your_password’ with a strong password.
Step 3: Exit the PostgreSQL Shell
\q
6. Configure Mattermost
Step 1: Edit the Configuration File
Navigate to the Mattermost configuration directory:
cd /opt/mattermost/config
Open config.json in a text editor:
sudo nano config.json
Find the SqlSettings section and update it with your database details:
"SqlSettings": { "DriverName": "postgres", "DataSource": "mattermost:your_password@localhost/mattermost_db?sslmode=disable" }
Make sure to replace your_password with the password you set for the mattermost user.
Step 2: Save and Exit
Save the changes and exit the text editor.
7. Start Mattermost
To start Mattermost, navigate to the Mattermost directory and run the following command:
sudo -u mattermost /opt/mattermost/bin/mattermost
8. Configure Nginx
Step 1: Create a Nginx Configuration File
Create a new configuration file for Mattermost:
sudo nano /etc/nginx/sites-available/mattermost
Add the following configuration:
server { listen 80; server_name your_domain.com; # Replace with your domain location / { proxy_pass http://localhost:8065; proxy_set_header Host $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; } }
Step 2: Enable the Configuration
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
Step 3: Test Nginx Configuration
Check for syntax errors in the Nginx configuration:
sudo nginx -t
Step 4: Restart Nginx
Restart Nginx to apply the changes:
sudo systemctl restart nginx