install mattermost

Jump toUpdate content

Installing Mattermost Messaging on Ubuntu 18.04

Reviewed on 18 January 2022Published on 22 January 2019
  • compute
  • communication
  • messaging
  • Mattermost
  • Slack
  • Ubuntu-Bionic-Beaver

Mattermost is an open-source messaging tool for inter-team communication, released under the MIT license and available both in a free team and paid enterprise edition. This tutorial will show you how to install a Mattermost instance with a NGINX frontend proxy and a MariaDB database.


Setting up MariaDB

  1. Connect to your instance via SSH.

  2. Update the APT packet cache and the software already installed on the instance.

    apt update && apt upgrade -y
  3. Install the MariaDB database server.

    apt install mariadb-server
  4. Launch the database server.

  5. Log in to mysql as root:

    mysql -u root -p
  6. Create a database for Mattermost:

    create user 'mattermost'@'localhost' identified by 'a-secure-password';

    Replace a-secure-password with a strong password, as it will be used to login to MariaDB

  7. Create a database for Mattermost whilst being logged into the MariaDB shell:

    create database mattermost;
  8. Grant access privileges to the user mattermost.

    grant all privileges on mattermost.* to 'mattermost'@'localhost';
  9. Exit the MariaDB shell.


Installing Mattermost

  1. Download the latest version of the Mattermost server to your instance.

    wget https://releases.mattermost.com/6.3.0/mattermost-6.3.0-linux-amd64.tar.gz
  2. Extract the Mattermost server files.

    tar -xvzf mattermost*.gz
  3. Move the extracted files to the /opt directory.

    mv mattermost /opt
  4. Create the storage directory for Mattermost.

    mkdir /opt/mattermost/data

    This directory will contain all data sent to your Mattermost instance (Messages, Images, Files etc.). Make sure that it has enough space available for the anticipated number of contents sent to your instance.

  5. Set up a system user and group to be in charge of running the service and set the ownership and permissions as following:

    • Create a system user and group called mattermost:
    useradd --system --user-group mattermost
    • Set the ownership of the Mattermost files to the previously created user and group:
    chown -R mattermost:mattermost /opt/mattermost
    • Give write permissions to the mattermost group.
    chmod -R g+w /opt/mattermost
  6. Open the file /opt/mattermost/config/config.json with your favorite text editor and edit the database settings as following.

    • Set the "DriverName" to mysql
    • Configure "DataSource" as following, replacing <a-secret-password> with the password you have set for your database.
  7. Start the Mattermost server manually to check everything is working.

    sudo -u mattermost ./bin/mattermost

    During startup the database structure of Mattermost will be configured and you will see some log messages as well as a notice: Server is listening on :8065. This means your Mattermost server is now ready to be used. Stop the process by pushing Control+C on your keyboard.

  8. Open your favorite text editor and create the file /lib/systemd/system/mattermost.service with the following content to create a systemd script to run the application as-a-Service on your instance:



  9. Reload the systemd configuration.

    systemctl daemon-reload
  10. Start the service.

    systemctl start mattermost.service
  11. Enable the service to start Mattermost during the startup of the instance.

    systemctl enable mattermost.service

    You can now connect to your Mattermost server at http://your_servers_ip:8065 and create your first user and do some initial configuration and setup.

Installing an Nginx Proxy with Let’s Encrypt

For security reasons it is recommended to put the application behind a proxy. Nginx is being used as frontend for the application. To provide an encrypted connection, certbot is used to generate a free Let’s Encrypt SSL certificate to encrypt the connection to the instance.

  1. Install Nginx and Certbot.

    apt install nginx python-certbot-nginx -y
  2. Create a new server block for Mattermost (replace mattermost.example.com with the FQDN of your instance).

    touch /etc/nginx/sites-available/mattermost.example.com

    And enter the following content in the file:

    upstream backend {
    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.example.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://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_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://backend;
  3. Remove the default server block of Nginx.

    rm /etc/nginx/sites-enabled/default
  4. Enable the Mattermost server block by linking it to the sites-enabled directory:

    ln -s /etc/nginx/sites-available/mattermost.example.com /etc/nginx/sites-enabled/mattermost.example.com
  5. Restart Nginx:

    sudo service nginx restart
  6. Run Certbot.


    The application will ask you several questions. You have to confirm the steps as described. For more information refer to our documentation about certbot.

Setting up Mattermost

  1. Connect to your instance by going to https://your_servers_ip. The Mattermost login screen will appear. Connect yourself with the user you have created during the initial setup of the application.

  2. Once logged in click the menu button, then on System Console to enter the configuration interface of Mattermost.

  3. Click Configuration in the general settings section.

  4. Configure the Listen Address as

    This prevents direct connections to Mattermost from other machines.

  5. Restart the Mattermost service.

    systemctl restart mattermost.service
  6. Reload the Mattermost application in your browser.

You may configure advanced settings, like email notifications and other customizations of your Mattermost application. For more information, refer to the official documentation.