How To Install Mattermost on Ubuntu 22.04

This guide intends to teach you to Install Mattermost on Ubuntu 22.04. Mattermost is a popular team messaging system and it is open-source. In this guide, you will learn to set up Mattermost with Apache as a web server and MariaDB as a database management system.

How To Install Mattermost on Ubuntu 22.04?

To complete this guide, you must access your server as a non-root user with sudo privileges and set up a basic firewall. For this purpose, you can follow our guide on Initial Server Setup with Ubuntu 22.04.

Also, you need a domain name that pointed to your server’s IP address.

Step 1 – Install and Configure MariaDB for Mattermost

As we said in this guide, we will use MariaDB as our database management system. So you need to run the system update and install the MariaDB server with the following commands:

# sudo apt update
# sudo apt install mariadb-server -y

Then, secure your MariaDB installation and set a root password for your MariaDB by using the following script:

sudo mysql_secure_installation
Enter current password for root (enter for none):
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
New password:
Re-enter new password:
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
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Now proceed to the following step to configure MariaDB for Mattermost.

Create a Mattermost Database and Database User

At this point, you need to log in to your MariaDB shell with the following command:

sudo mysql -u root -p

Then, you must create a Mattermost database and database user with a password on Ubuntu 22.04. To do this, run the following commands:

MariaDB [(none)]> CREATE DATABASE mattermostdb;
MariaDB [(none)]> CREATE USER 'orca'@'%';
MariaDB [(none)]> SET PASSWORD FOR 'orca'@'%' = PASSWORD('strongpassword');

Next, you need to give all the privileges to the Mattermost database and database user with the command below:

MariaDB [(none)]> GRANT ALL ON mattermostdb.* TO 'orca'@'%' IDENTIFIED BY 'strongpassword' WITH GRANT OPTION;

Next, flush the privileges and exit from the MariaDB console:

MariaDB [(none)]> EXIT;

Step 2 – Install Mattermost on Ubuntu 22.04

At this point, you need to create a dedicated user and group for Mattermost. To do this, you can use the following command:

sudo useradd --system --user-group mattermost

Then, you need to visit the Mattermost release page and get the latest version by using the following wget command on your Ubuntu 22.04:

sudo wget

When your download is completed, extract your file in the /opt directory:

sudo tar xvzf mattermost-7.10.2-linux-amd64.tar.gz -C /opt/

Next, use the following command to install a data directory to store your Mattermost files:

sudo mkdir /opt/mattermost/data

Now set the correct permission and ownership by using the following commands:

# sudo chown -R mattermost:mattermost /opt/mattermost
# sudo chmod -R g+w /opt/mattermost

Step 3 – Configure Mattermost on Ubuntu 22.04

At this point, you need to edit the Mattermost configuration file and define your site URL and database settings to the file. To do this, open the Mattermost config file with your desired text editor, here we use the vi editor:

sudo vi /opt/mattermost/config/config.json

At the file, define your site URL and database settings as shown below:

"SiteURL": "", 
"DriverName": "mysql", 
"DataSource": "orca:strongpassword@tcp(hostname-or-ip:3306)/mattermostdb?charset=utf8mb4,utf8&writeTimeout=30s",

When you are done, save and close the file.

Then, change to the Mattermost directory and Start the Mattermost server as the user mattermost with the following command:

# cd /opt/mattermost

# sudo -u mattermost ./bin/mattermost

When the server starts, you will see some log information and the text Server is listening on :8065. Then, you can stop the server by pressing pressing Ctrl C.

Step 4 – Create a Systemd Unit File for Mattermost on Ubuntu 22.04

At this point, you need to create a systemd unit file to manage your Mattermost service. To do this, run the command below:

sudo vi /etc/systemd/system/mattermost.service

Add the following content to the file:

Description=Mattermost mysqld.service



Set the service file permissions with the following command:

sudo chmod 644 /etc/systemd/system/mattermost.service

    Now reload the systemd service to apply the changes:

    sudo systemctl daemon-reload

    Next, use the following commands to start and enable your service to start at boot:

    # sudo systemctl start mattermost
    # sudo systemctl enable mattermost

    Verify that your Mattermost service is active and running on Ubuntu 22.04:

    sudo systemctl status mattermost

    In your output you will see:

    ● mattermost.service - Mattermost
         Loaded: loaded (/etc/systemd/system/mattermost.service; enabled; vendor preset: enabled)
         Active: active (running) since Mon 2023-05-29 08:28:53 UTC; 4min 17s ago
       Main PID: 4485 (mattermost)
          Tasks: 54 (limit: 4575)
         Memory: 427.8M
            CPU: 15.924s
         CGroup: /system.slice/mattermost.service
                 ├─4485 /opt/mattermost/bin/mattermost
                 ├─4495 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64

    Step 5 – Configure Apache for Mattermost

    At this point, that you have installed Mattermost on Ubuntu 22.04, you need to configure Apache as a reverse proxy for Mattermost.

    First, install Apache on Ubuntu 22.04 with the following command:

    sudo apt install apache2 -y

    Then, you need to enable Apache modules with the commands below:

    # sudo a2enmod rewrite
    # sudo a2enmod proxy
    # sudo a2enmod proxy_http
    # sudo a2enmod proxy_wstunnel

    Next, you need to create an Apache virtual host configuration file. Create and open the file with your favorite text editor, here we use vi:

    sudo vi /etc/apache2/sites-available/mattermost.conf

    Add the following contents to the file:

    <VirtualHost *:80>
    ProxyPreserveHost On
    RewriteEngine On
    RewriteCond %{REQUEST_URI} /api/v[0-9]+/(users/)?websocket [NC]
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} \bUpgrade\b [NC]
    RewriteRule .* ws://{REQUEST_URI} [P,QSA,L]
    <Location />
    Require all granted

    Remember to replace the domain names with your own in the file.

    When you are done, save and close the file.

    Now activate Apache virtual host file with the following command:

    sudo ln -s /etc/apache2/sites-available/mattermost.conf /etc/apache2/sites-enabled/mattermost.conf

    Restart Apache to apply the changes:

    sudo systemctl restart apache2

    Step 6 – Configure Firewall for Matetrmost

    If you have a running UFW firewall, you must allow port HTTP, HTTPS, and port Mattermost which is 8065. To do this, you can run the commands below:

    # sudo ufw allow http
    # sudo ufw allow https
    # sudo ufw allow 8065

    To apply the new rules, reload the firewall:

    sudo ufw reload

    Step 7 – How To Access Mattermost Dashboard?

    At this point, you can access the Mattermost web interface by typing your server’s IP address or your domain name in your web browser followed by 8065:


    You will see the Mattermost create account screen, set your account and click Create Account as shown below:

    Create mattermost account

    In the next window, you can create a team or go to your system console:

    create mattermost team

    If you click on the system console you will see your Mattermost system console:

    Mattermost system console

    That’s it, you’ve just configured Mattermost to Ubuntu 22.04 Server. From there you can collaborate with your teams.

    Where is Mattermost default location on Ubuntu?

    The default configuration file of Mattermost is installed on the following location on Linux:


    In this guide, we installed Mattermost under the /opt directory, you can find your Mattermost files by using the command below:

    ls /opt/mattermost

    How to Update Mattermost in Ubuntu?

    To upgrade Mattermost, you can easily download the new package and back up your database settings, and upgrade your MAttermost service.

    For more information, you can visit the Mattermost Docs page.


    At this point, you have learned to Install and Configure the Mattermost team messaging system on Ubuntu 22.04 with MariaDB and Apache web server. Also, you have learned to Access your Mattermost dashboard from a web browser.

    Hope you enjoy it. You may be interested in these articles on the Orcacore website:

    Install and Use DirectAdmin on Ubuntu 22.04

    Install Nagios Monitoring Tool on Ubuntu 20.04

    Newsletter Updates

    Enter your email address below and subscribe to our newsletter

    Stay informed and not overwhelmed, subscribe now!