Mattermost is an open-source, self-hosted Slack alternative. Being free of the requirement to depend on a third-party vendor means that you are able to host your data in your own infrastructure.
There are many reasons why you would want or need this – security being one of the most prominent ones. Furthermore, having full control over all processes will greatly increase the reliability and uptime of your team communication platform.
You can use Mattermost in your browser, on mobile devices like Android and iOS, or integrate it with various other services via API or webhooks. Also, it’s very modular in its design; you are able to choose the components you actually need.
In this tutorial, we will walk through the steps required to install Mattermost on Rocky Linux 8.
This article is based on the Community Edition of Mattermost, which is freely available for download at its official website. Other Editions are also available there – you could start with the Enterprise Edition if you have a bigger team or require more extended security features, an on-premise solution instead of self-hosting, voice chat, etc.
Prerequisites
To be able to install and run Mattermost, a few assumptions will have to be made.
- You are a user with sudo access.
- At least 2 GB of RAM is recommended for comfortable work.
Step 1. Updating the System
First of all, you should update your system before its initial installation. Run the following commands in order to achieve this.
sudo dnf update
Press Y when asked if you want to continue with the installation.
Step 2. Installing MySQL Server Database for Mattermost
MySQL is a relational database management system widely used for various web applications’ backend storage. Mattermost can use either MySQL or PostgreSQL. For simplification, we will install MySQL in this article – make sure to adjust your setup if you need to use PostgreSQL instead of MySQL.
You can skip this step if you already have MySQL up and running on your server.
Run the following command to install MySQL.
sudo dnf install mysql-server
Press Y and press Enter when asked if you want to continue with the installation.
Once the installation is complete, start and enable the MySQL service to make it start up at boot and after a system reboot:
sudo systemctl start mysqld.service sudo systemctl enable mysqld.service
The MySQL service should have started successfully. Let’s check if everything is in order by checking its status.
systemctl status mysql.service
You’ll see an output similar to the one below.
Step 3. Creating a Database for Mattermost
Mattermost uses a database to store its data, like almost every other modern application. Therefore, we will need to create a MySQL database for it.
First, log in to the MySQL shell with the mysql command:
mysql -u root -p
Enter your password when asked.
Next, you will need to create a database for Mattermost. In this example, we will create a lwdb using the CREATE DATABASE statement. You can choose a custom name for your database if you want.
CREATE DATABASE lwdb;
Next, we will need to create a database user who can connect to the database. We will create a user called lwuser with the password $trongp@ssword. Change the password to something more secure if you prefer.
CREATE USER 'lwuser'@'localhost' IDENTIFIED BY '$trongp@ssword';
We will also need to grant the user full access to the database we created. We do this using GRANT statements.
GRANT ALL PRIVILEGES ON lwdb.* TO lwuser@localhost;
Reload the privilege table to apply the changes.
FLUSH PRIVILEGES;
Exit back to your shell.
quit;
Sample output:
Step 4. Installing the Mattermost Server
In this step, we will download a Mattermost binary file manually and install it on your server.
Open your web page, navigate to:
https://mattermost.com/download/
Find the latest release. As of writing, it is v5.39.0. Right-click on the release number and copy the link location.
Once you have copied the URL, run the following wget command to download the latest release to the current directory. Make sure to check and replace for an updated version.
wget https://releases.mattermost.com/5.39.0/mattermost-5.39.0-linux-amd64.tar.gz
This will download a file called mattermost-5.39.0-linux-amd64.tar.gz to your current directory.
Now, we will extract the downloaded file with the tar command. After that, we will move the extracted files to the /opt directory.
tar -xf mattermost-*-linux-amd64.tar.gz
sudo mv mattermost /opt
Once this is done, we will clean up by removing the files that were just downloaded
sudo rm -rf mattermost-5.39.0-linux-amd64.tar.gz
Step 5. Configuring the config.json File
In this step, we will edit a configuration file for the Mattermost server. This will allow us to adjust the settings to our preferences.
First, open up a terminal window and navigate to /opt/mattermost/config/ directory and open the config.json file with the nano editor.
cd /opt/mattermost/config/
sudo nano config.json
The editor should open the config.json file in the terminal window.
Edit the following lines of the file to point Mattermost to your MySQL server. You can leave everything else as is. This will be ignored if you are using PostgreSQL instead of MySQL. We have highlighted in red what you need to edit..
In DriverName: Change postgres to mysql.
In the DataSource section.
Replace:
- mmuser: replace this value with the user you set for the MySQL database.
- mostest: replace this value with t MySQL database password.
- mattermost_test: replace this value with your MySQL database name
In the end, your DataSource line will end up like this.
Save the file by pressing Ctrl+X, Y, and Enter.
Step 6. Creating a Systemd Unit File for Mattermost
Next, we will create a systemd unit file for Mattermost. systemd is responsible for running services in Linux. Hence, we can start, stop, and restart the Mattermost server.
We will name our service file mattermost.service. Feel free to replace the service name with your own preference.
cd /etc/systemd/system/
sudo nano mattermost.service
Copy and paste the below contents into the file. Make sure to check, replace where necessary for your own preferences.
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 LimitNOFILE=49152 [Install] WantedBy=multi-user.target
Save and exit the file when you are finished. Make the file executable by changing the file permissions.
sudo chmod 664 /etc/systemd/system/mattermost.service
Reload the systemd service to apply the changes with:
sudo systemctl daemon-reload
Now you can use the following commands to manage it:
sudo systemctl start mattermost.service sudo systemctl stop mattermost.service sudo systemctl restart mattermost.service
To check the status of the Mattermost service, run:
sudo systemctl status mattermost.service
You will see a result that looks like this. As you can see, the command also tells us that the Mattermost service is currently up and running.
Step 7. Accessing the Mattermost Web UI
Now, in order to access Mattermost in your browser, you will need to find the public IP for your server.
To do so, run:
ip a
This should return an IP address. This is the IP address we will use when we visit the Mattermost web interface.
Open up your web browser and navigate to https://<server_IP>:8065/ to access the Mattermost web UI.
You should see a screen similar to the one below. You will be prompted to create an admin account. Provide an email, an username, a password to create, and click on Create Account to create an administrator account.
Once the authorization is complete, you will be taken to the Mattermost dashboard. Now you are ready to start creating teams, channels and sharing files with Mattermost.
The Mattermost installation is now complete. For further reading on how to use Mattermost, you can check out its official documentation.
Conclusion
In this tutorial, you have learned how to install Mattermost on a Rocky Linux 8.4 server. You can now create teams, channels and share files with this open-source Slack alternative.