Install Mattermost on Ubuntu 22.04: Popular Messaging System
This guide provides a comprehensive walkthrough on how to Install Mattermost on Ubuntu 22.04. Mattermost is a widely adopted, open-source team messaging platform that offers a self-hosted alternative to services like Slack. This tutorial, brought to you by Orcacore, details the process of setting up Mattermost using Apache as a web server and MariaDB as the database management system.
Before you begin the process to Install Mattermost on Ubuntu 22.04, ensure you have the following prerequisites:
- Access to an Ubuntu 22.04 server as a non-root user with sudo privileges. A basic firewall should also be configured. Refer to Orcacore’s guide on Initial Server Setup with Ubuntu 22.04 for assistance with this.
- A domain name that resolves to your server’s IP address.
Let’s begin the process to Install Mattermost on Ubuntu 22.04.
Step 1 – Install and Configure MariaDB for Mattermost
This guide utilizes MariaDB for managing Mattermost’s data. Begin by updating the system package list and installing the MariaDB server:
# sudo apt update
# sudo apt install mariadb-server -y
Next, secure the MariaDB installation by running the mysql_secure_installation
script. This script helps set a root password, remove anonymous users, disallow remote root login, and remove the test database.
sudo mysql_secure_installation
The script will prompt you with a series of questions. An example interaction is shown below:
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!
Create a Mattermost Database and Database User
After securing MariaDB, log in to the MariaDB shell as the root user:
sudo mysql -u root -p
Within the MariaDB shell, create a dedicated database for Mattermost, a database user, and assign a strong password to that user. Replace <mark>mattermostdb</mark>
, <mark>orca</mark>
, and <mark>strongpassword</mark>
with your desired database name, username, and password, respectively.
-- MariaDB [(none)]> CREATE DATABASE <mark>mattermostdb</mark>;
-- MariaDB [(none)]> CREATE USER '<mark>orca</mark>'@'%';
-- MariaDB [(none)]> SET PASSWORD FOR '<mark>orca</mark>'@'%' = PASSWORD('<mark>strongpassword</mark>');
Grant the newly created user full privileges on the Mattermost database:
-- MariaDB [(none)]> GRANT ALL ON <mark>mattermostdb</mark>.* TO '<mark>orca</mark>'@'%' IDENTIFIED BY '<mark>strongpassword</mark>' WITH GRANT OPTION;
Finally, flush the privilege tables to apply the changes and exit the MariaDB shell:
-- MariaDB [(none)]> FLUSH PRIVILEGES;
-- MariaDB [(none)]> EXIT;
Step 2 – Install Mattermost on Ubuntu 22.04
Create a dedicated system user and group for Mattermost to enhance security:
sudo useradd --system --user-group <mark>mattermost</mark>
Download the latest Mattermost package from the Mattermost release page. Use the wget
command to download the package directly to your server. This example uses version 7.10.2, but check the Mattermost website for the latest version.
sudo wget https://releases.mattermost.com/7.10.2/mattermost-7.10.2-linux-amd64.tar.gz
Extract the downloaded archive to the /opt
directory:
sudo tar xvzf mattermost-7.10.2-linux-amd64.tar.gz -C /opt/
Create a data directory for storing Mattermost files:
sudo mkdir /opt/mattermost/data
Set the correct ownership and permissions for the Mattermost directory:
# sudo chown -R mattermost:mattermost /opt/mattermost
# sudo chmod -R g+w /opt/mattermost
Step 3 – Configure Mattermost on Ubuntu 22.04
Edit the Mattermost configuration file (config.json
) to specify the site URL and database settings.
sudo vi /opt/mattermost/config/config.json
Locate the "SiteURL"
, "DriverName"
, and "DataSource"
parameters within the file and modify them as follows. Replace <mark>https://mattermost.example.com</mark>
, <mark>orca:strongpassword</mark>
, and <mark>hostname-or-ip</mark>
with your actual site URL, database credentials, and database server address, respectively.
"SiteURL": "<mark>https://mattermost.example.com</mark>",
"DriverName": "<mark>mysql</mark>",
"DataSource": "<mark>orca:strongpassword</mark>@tcp(<mark>hostname-or-ip</mark>:3306)/<mark>mattermostdb</mark>?charset=utf8mb4,utf8&writeTimeout=30s",
Save the changes and close the file.
Change to the Mattermost directory and start the Mattermost server as the mattermost
user:
# cd /opt/mattermost
# sudo -u mattermost ./bin/mattermost
Once the server starts, you should see log messages indicating that the server is listening on port 8065. You can then stop the server by pressing Ctrl
+ C
.
Step 4 – Create a Systemd Unit File for Mattermost on Ubuntu 22.04
Create a systemd unit file to manage the Mattermost service.
sudo vi /etc/systemd/system/mattermost.service
Add the following content to the file:
[Unit]
Description=Mattermost
After=syslog.target network.target mysqld.service
[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
ExecStart=/opt/mattermost/bin/mattermost
PIDFile=/var/spool/mattermost/pid/master.pid
TimeoutStartSec=3600
KillMode=mixed
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target
Set the appropriate permissions for the service file:
sudo chmod 644 /etc/systemd/system/mattermost.service
Reload the systemd daemon to apply the changes:
sudo systemctl daemon-reload
Start and enable the Mattermost service:
# sudo systemctl start mattermost
# sudo systemctl enable mattermost
Verify that the Mattermost service is running:
sudo systemctl status mattermost
The output should indicate that the service is active
and running
.
Output
● 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
Install Apache:
sudo apt install apache2 -y
Enable the necessary Apache modules:
# sudo a2enmod rewrite
# sudo a2enmod proxy
# sudo a2enmod proxy_http
# sudo a2enmod proxy_wstunnel
Create an Apache virtual host configuration file:
sudo vi /etc/apache2/sites-available/mattermost.conf
Add the following content to the file, replacing <mark>admin@example.com</mark>
and <mark>mattermost.example.com</mark>
with your actual email address and domain name:
<VirtualHost *:80>
ServerAdmin <mark>admin@example.com</mark>
ServerName <mark>mattermost.example.com</mark>
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{REQUEST_URI} /api/v[0-9]+/(users/)?websocket [NC]
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} bUpgradeb [NC]
RewriteRule .* ws://127.0.0.1:8065%{REQUEST_URI} [P,QSA,L]
<Location />
Require all granted
ProxyPass http://127.0.0.1:8065/
ProxyPassReverse http://127.0.0.1:8065/
ProxyPassReverseCookieDomain 127.0.0.1 <mark>mattermost.example.com</mark>
</Location>
</VirtualHost>
Activate the virtual host:
sudo ln -s /etc/apache2/sites-available/mattermost.conf /etc/apache2/sites-enabled/mattermost.conf
Restart Apache:
sudo systemctl restart apache2
Step 6 – Configure Firewall for Mattermost
Allow HTTP, HTTPS, and Mattermost’s default port (8065) through the firewall:
# sudo ufw allow http
# sudo ufw allow https
# sudo ufw allow 8065
Reload the firewall:
sudo ufw reload
Step 7 – How To Access Mattermost Dashboard?
Access the Mattermost web interface by navigating to your server’s IP address or domain name in your web browser:
http://<mark>your-domain-name-or-IP</mark>:8065
You should be presented with the Mattermost create account screen. Create your account and proceed to set up your team.



You have successfully installed and configured Mattermost on Ubuntu 22.04. You can now begin collaborating with your team.
Conclusion
This guide demonstrated how to Install Mattermost on Ubuntu 22.04 using MariaDB for data management and Apache as a reverse proxy. You also learned how to access the Mattermost dashboard through a web browser.
Here are some other articles you may find helpful:
Install and Use DirectAdmin on Ubuntu 22.04
Install Nagios Monitoring Tool on Ubuntu 20.04
FAQs
Where is Mattermost default location on Ubuntu?
The default configuration file of Mattermost is installed on the following location on Linux: ~/.config/Mattermost
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, back up your database settings, and upgrade your MAttermost service.
Alternative Solutions for Installing Mattermost on Ubuntu 22.04
While the above guide outlines a common and effective method for installing Mattermost, alternative approaches exist. Here are two different ways to achieve the same goal, along with explanations and code examples.
Alternative 1: Using Docker Compose
Docker Compose provides a streamlined way to define and manage multi-container Docker applications. This method simplifies the deployment of Mattermost and its dependencies (database, etc.) by encapsulating them within Docker containers.
-
Explanation: Docker Compose uses a YAML file (
docker-compose.yml
) to define the services, networks, and volumes required for the application. This approach offers several advantages:- Isolation: Each component runs in its own container, preventing conflicts and ensuring consistency.
- Reproducibility: The
docker-compose.yml
file acts as a blueprint, making it easy to recreate the environment on different machines. - Scalability: Docker Compose facilitates scaling the application by increasing the number of containers for each service.
-
Steps:
-
Install Docker and Docker Compose:
sudo apt update sudo apt install docker.io docker-compose -y
-
Create a
docker-compose.yml
file:sudo vi docker-compose.yml
-
Add the following content to the
docker-compose.yml
file:version: "3.9" services: db: image: "mariadb:10.6" volumes: - db_data:/var/lib/mysql restart: unless-stopped environment: MYSQL_ROOT_PASSWORD: "your_root_password" MYSQL_USER: "mattermost" MYSQL_PASSWORD: "your_mattermost_password" MYSQL_DATABASE: "mattermost" mattermost: image: "mattermost/mattermost-team-edition:latest" depends_on: - db ports: - "8065:8065" - "8067:8067" volumes: - mattermost_data:/mattermost_data - ./config:/mattermost/config # Mount the config directory restart: unless-stopped environment: MM_SQLSETTINGS_DRIVERNAME: "mysql" MM_SQLSETTINGS_DATASOURCE: "mattermost:your_mattermost_password@tcp(db:3306)/mattermost?charset=utf8mb4,utf8&writeTimeout=30s" MM_SERVICESETTINGS_SITEURL: "http://your_domain_or_ip:8065" MM_SERVICESETTINGS_LISTENADDRESS: ":8065" volumes: db_data: mattermost_data:
- Note: Replace
"your_root_password"
,"your_mattermost_password"
, and"http://your_domain_or_ip:8065"
with your actual root password, Mattermost database user password, and your server’s URL, respectively. Creating a./config
directory next todocker-compose.yml
and placing theconfig.json
file there will allow you to customize your config without rebuilding the container.
- Note: Replace
-
Start the Mattermost containers:
sudo docker-compose up -d
-
Access Mattermost: Open your web browser and navigate to
http://your_domain_or_ip:8065
.
-
Alternative 2: Using a Pre-built Mattermost AMI (Amazon Machine Image) on AWS
If you’re using AWS, deploying a pre-built Mattermost AMI can significantly simplify the installation process.
-
Explanation: AWS Marketplace offers pre-configured AMIs that include Mattermost and all its dependencies. This eliminates the need for manual installation and configuration, allowing you to quickly deploy Mattermost on AWS.
-
Steps:
- Log in to the AWS Management Console.
- Navigate to the AWS Marketplace.
- Search for "Mattermost".
- Select a Mattermost AMI that suits your needs (e.g., one with built-in backups or specific configurations).
- Click "Continue to Subscribe".
- Review the terms and conditions and click "Accept Terms".
- Click "Continue to Configuration".
- Choose the desired region and instance type.
- Configure the instance details (security groups, key pair, etc.).
- Launch the instance.
- Access Mattermost: After the instance is launched, obtain the public IP address of the instance and access Mattermost through your web browser (e.g.,
http://your_instance_ip
). You may need to configure DNS to point your domain to the instance’s IP address. The initial setup instructions are typically provided by the AMI vendor.
These alternative solutions offer different approaches to installing Mattermost, catering to various preferences and environments. The Docker Compose method provides greater control and portability, while the AWS AMI option simplifies deployment within the AWS ecosystem. Choose the method that best aligns with your needs and expertise.