In this tutorial, we will show you how to install Mattermost on Ubuntu 20.04 LTS. For those of you who didn’t know, Mattermost is an open-source and self-hosted messaging application used for chat, file sharing, search, and integrations written in Golang and React. It is an alternative to Slack and provides a chat service with file sharing, search, and integrations. It is designed for organizations and companies and allows teams to communicate and collaborate securely from everywhere.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Mattermost on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Mattermost on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing the LEMP stack.
A Ubuntu 20.04 LEMP server is required. If you do not have LEMP installed, you can follow our guide here.
Step 3. Installing Mattermost on Ubuntu 20.04.
Create a separate user and group to run Mattermost, you can create it with the following command:
useradd --system --user-group mattermost
Now we download the latest version of Mattermost from its official website:
wget https://releases.mattermost.com/5.28.1/mattermost-5.28.1-linux-amd64.tar.gz
Once downloaded, unpack the Mattermost archive to the document root directory on your server:
tar -xvzf mattermost-5.28.1-linux-amd64.tar.gz mv mattermost /opt/ mkdir /opt/mattermost/data
We will need to change some folders permissions:
chown -R mattermost:mattermost /opt/mattermost chmod -R g+w /opt/mattermost
After that, edit the Mattermost configuration file and define your site URL and database settings:
nano /opt/mattermost/config/config.json
Change the following lines as per your need:
"SiteURL": "http://mattermost.example.com", "DriverName": "mysql", "DataSource": "mattermost:secure-your-password@tcp(localhost:3306)/mattermostdb?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",
Step 4. Configuring MariaDB for Mattermost.
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
mysql_secure_installation
Configure it like this:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
Next, we will need to log in to the MariaDB console and create a database for the Mattermost. Run the following command:
mysql -u root -p
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Mattermost installation:
MariaDB [(none)]> CREATE DATABASE mattermostdb; MariaDB [(none)]> CREATE USER 'mattermost'@'%' IDENTIFIED BY 'your-secure-password'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mattermost'@'%'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
Step 5. Create a Systemd Service File for Mattermost.
Now we create a systemd
service file to manage the Mattermost service. You can create it with the following command:
nano /lib/systemd/system/mattermost.service
Add the following lines:
[Unit] Description=Mattermost After=network.target After=mysql.service Requires=mysql.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=mariadb.service
Save and close the file then reload the systemd
daemon with the following command:
sudo systemctl daemon-reload sudo systemctl start mattermost sudo systemctl enable mattermos
Step 6. Configure Nginx as a Reverse Proxy.
Now create an Nginx virtual host configuration file with the following command:
nano /etc/nginx/sites-available/mattermost.conf
Add the following lines:
upstream mattermost { server localhost:8065; keepalive 32; } proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off; server { listen 80; server_name mattermost.idroot.us; 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; client_body_timeout 65; send_timeout 200; lingering_timeout 5; proxy_connect_timeout 80; proxy_send_timeout 300; proxy_read_timeout 80s; proxy_pass http://mattermost; } 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_cache mattermost_cache; proxy_cache_revalidate on; proxy_cache_min_uses 2; proxy_cache_use_stale timeout; proxy_cache_lock on; proxy_http_version 1.1; proxy_pass http://mattermost; } }
Save and close the file then activate the virtual host configuration with the following command:
ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf sudo systemctl restart nginx
Step 7. Set up HTTPS.
We should enable a secure HTTPS connection on Nextcloud. We can obtain a free TLS certificate from Let’s Encrypt. Install Let’s Encrypt client (Certbot) from Ubuntu 20.04 repository:
sudo apt install python3-certbot-nginx
Next, run the following command to install the Let’s Encrypt SSL for your website:
certbot --nginx -d mattermost.idroot.us
If the test is successful, reload Nginx for the change to take effect:
sudo nginx -t sudo systemctl restart nginx
Step 8. Configure Firewall.
Run the following command to open HTTP and HTTPS service ports:
sudo ufw allow 'Nginx Full'
Step 9. Accessing Mattermost.
Mattermost will be available on HTTP port 80 by default. Open your favorite browser and navigate to https://mattermost.idroot.us
and continue to configure Mattermost by entering an email address and creating an account.
Congratulations! You have successfully installed Mattermost. Thanks for using this tutorial for installing the Mattermost on your Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you to check the official Mattermost website.