How to Install Mattermost Team Messaging System on Ubuntu 20.04
This tutorial exists for these OS versions
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
On this page
Mattermost is an open-source and self-hosted messaging application used for chat, file sharing, search, and integrations. It is an alternative to Slack chat that brings all your team communication into one place. It is written in React and Golang, and uses PostgreSQL or MySQL database in the backend. It offers a rich set of features including, Push Notifications, Unlimited search history, Custom emojis, Webhooks & commands, Active directory, Multi-node database deployment support, Forum, Discussion Board and many more.
In this tutorial, we will show you how to install Mattermost with Nginx and Let's Encrypt SSL on Ubuntu 20.04.
Prerequisites
- A server running Ubuntu 20.04.
- A valid domain name pointed with your server IP.
- A root password is configured on the server.
Getting Started
First, it is recommended to update your system packages with the latest version. You can update them by running the following command:
apt-get update -y
Once all the packages are updated, install other required dependencies by running the following command:
apt-get install curl wget vim git unzip gnupg2 -y
After installing all required packages, you can proceed to the next step.
Install and Configure MariaDB
Mattermost uses MySQL/MariaDB as a database backend. So the MariaDB server must be installed in your server. If not installed, you can install it with the following command:
apt-get install mariadb-server -y
After installing MariaDB server, log in to the MariaDB with the following command:
mysql
Once login, create a database and user for Mattermost with the following command:
MariaDB [(none)]> CREATE DATABASE mattermostdb;
MariaDB [(none)]> CREATE USER 'mattermost'@'%' IDENTIFIED BY 'password';
Next, grant all the privileges to the Mattermost with the following command:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mattermost'@'%';
Next, flush the privileges and exit from the MariaDB shell with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Once your MariaDB database is configured, you can proceed to the next step.
Install and Configure Mattermost
First, you will need to download the latest version of Mattermost from its official website. You can download it with the following command:
wget https://releases.mattermost.com/5.24.2/mattermost-5.24.2-linux-amd64.tar.gz
Once downloaded, extract the downloaded file with the following command:
tar -xvzf mattermost-5.24.2-linux-amd64.tar.gz
Next, copy the extracted directory to the /opt:
cp -r mattermost /opt
Next, create a data directory for Mattermost:
mkdir /opt/mattermost/data
Next, you will need to create a separate user to run Mattermost. You can create it with the following command:
useradd --system --user-group mattermost
Next, change the ownership of the mattermost directory to mattermost and give proper permissions with the following command:
chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost
Next, edit the Mattermost default configuration file and define your database settings and site URL.
nano /opt/mattermost/config/config.json
Change the following lines as per your need:
"SiteURL": "https://mattermost.linuxbuz.com", "DriverName": "mysql", "DataSource": "mattermost:password@tcp(localhost:3306)/mattermostdb?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",
Save and close the file when you are finished.
Create a Systemd Service File for Mattermost
Next, you will need to 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 relaod the systemd daemon with the following command:
systemctl daemon-reload
Next, start the Mattermost service and enable it to start at system reboot with the following command:
systemctl start mattermost
systemctl enable mattermost
Next, verify the status of the Mattermost service with the following command:
systemctl status mattermost
You should get the following output:
? mattermost.service - Mattermost Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled) Active: active (running) since Sat 2020-08-01 09:12:52 UTC; 17s ago Main PID: 4106 (mattermost) Tasks: 20 (limit: 2353) Memory: 85.9M CGroup: /system.slice/mattermost.service ??4106 /opt/mattermost/bin/mattermost ??4198 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64 Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.131499,"caller":"mlog/sugar.go:19","msg":"Sent notification of ne> Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.1841655,"caller":"jobs/workers.go:73","msg":"Starting workers"} Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.1842792,"caller":"bleveengine/bleve.go:267","msg":"UpdateConf Ble> Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.1930475,"caller":"jobs/schedulers.go:74","msg":"Starting schedule> Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.20063,"caller":"app/web_hub.go:83","msg":"Starting websocket hubs> Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2099638,"caller":"app/license.go:37","msg":"License key from http> Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2205582,"caller":"app/server.go:525","msg":"Starting Server..."} Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2208374,"caller":"app/server.go:594","msg":"Server is listening o> Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2211802,"caller":"commands/server.go:106","msg":"Sending systemd > Aug 01 09:12:52 ubuntu2004 systemd[1]: Started Mattermost.
At this point, Mattermost is running and listening on port 8065.
Configure Nginx as a Reverse Proxy
Next, you will need to configure Nginxx as a reverse proxy for Mattermost. First, install the Nginx package with the following command:
apt-get install nginx -y
Once installed, 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.linuxbuz.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; client_body_timeout 60; send_timeout 300; lingering_timeout 5; proxy_connect_timeout 90; proxy_send_timeout 300; proxy_read_timeout 90s; 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
Next, verify the Nginx for any configuration error:
nginx -t
You should get the following output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, restart the Nginx service to apply the changes:
systemctl restart nginx
Secure Mattermost with Let's Encrypt SSL
First, you will need to install the Certbot client in your system to manage the Let's Encrypt SSL. You can install it with the following command:
apt-get install python3-certbot-nginx -y
After installing Certbot, run the following command to install the Let's Encrypt SSL for your website.
certbot --nginx -d mattermost.linuxbuz.com
You will be asked to provide a valid email address and accept the term of service as shown below:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for mattermost.linuxbuz.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/mattermost.conf
Next, select whether or not to redirect HTTP traffic to HTTPS:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Type 2 and hit Enter to install the Let's Encrypt SSL on your domain. Once installed, you should see the following output:
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/mattermost.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://mattermost.linuxbuz.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=mattermost.linuxbuz.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/mattermost.linuxbuz.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/mattermost.linuxbuz.com/privkey.pem Your cert will expire on 2020-10-30. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le - We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
Access Mattermost Web Interface
Now, open your web browser and type the URL https://mattermost.linuxbuz.com. You will be redirected to the Mattermost sign up screen:
Provide your email address, name, password and click on the Create Account button. You should see the following screen:
Click on the Create a team button. You should see the following screen:
Provide your Team name and click on the Next button. You should see the following screen:
Provide your team URL and click on the Finish button. You should see the Mattermost Welcome screen:
Click on the Skip Tutorials button. You should see the Mattermost dashboard in the following screen:
Conclusion
In this guide, you learned how to install Mattermost Team Messaging application on Ubuntu 20.04 server. You also learned how to configure Nginx as a reverse proxy and secure it with Let's Encrypt SSL. You can now explore Mattermost services and work together with your team.