1. Home
  2. Linux
  3. Set up mattermost on linux

How to set up Mattermost on Linux

Tired of using Slack on Linux? Wanting to host your own Team-based message service on a server? You can set up Mattermost on Linux and use it instead. It’s an open-source alternative to Slack with similar features!

Before we begin

In this tutorial, we’ll be focusing on setting up the Mattermost server software on Ubuntu server 18.04 LTS (long-term support). Therefore, if you have a Linux server (or desktop computer that can stay on for long periods of time), it is imperative that you go to the official website, download Ubuntu Server and install it before we begin.

Why Ubuntu server? The reason we are focusing on Ubuntu is simple: it’s one of the easiest Linux server operating systems to get going. Furthermore, it’s LTS releases ensure that users will have support for their Mattermost setup for at least five years.

Note: If you’re interested in setting up the server component of Mattermost on Linux and don’t use Ubuntu Server, you’ll be able to find help on the official website.

Set up the Database

Mattermost needs a MySQL database software set up on Ubuntu server to function correctly. To install it open up a terminal and log into the server with SSH.

Once you’ve got a working terminal session open, use the Apt package manager to install MySQL to the system (if you don’t already have it).

sudo apt install mysql-server

MySQL will take a bit of time to set up on your Ubuntu machine. When it’s done, run the secure installation command to complete the installation.

sudo mysql_secure_installation

MySQL is done installing on Ubuntu server. The next step in the database creation process is to log in to the command-line interface as root.

Note: Be sure to use the root password set during the secure installation part of the guide.

sudo mysql

Make a new user for the SQL database. The username is mmuser.

create user 'mmuser'@'%' identified by 'mmuser-password';

Create the user mattermost database in MySQL.

create database mattermost;

Grant theĀ mmuser user account the ability to access the mattermost database.

grant all privileges on mattermost.* to 'mmuser'@'%';

Finally, exit the MySQL command-line interface and return to Bash.

exit

Install Mattermost server software

Mattermost server is hosted on the official website. It is possible to download it directly to your server with the wget program. To get the latest release of the server software, open up a terminal and run the following command.

Note: Mattermost has several versions available. If you need a newer version than what is covered in this guide, head over to the official download page and replace the link we used below with your desired release.

wget https://releases.mattermost.com/5.5.0/mattermost-5.5.0-linux-amd64.tar.gz

The server software is done downloading on your Ubuntu server. It’s now time to extract it from the TarGZ archive.

tar -xvzf mattermost*.gz

sudo mv mattermost /opt

sudo mkdir /opt/mattermost/data

Configure Mattermost server

The server software is set up on Ubuntu, but it won’t run until we configure it correctly. Configuration starts by creating the mattermostĀ user.

sudo useradd --system --user-group mattermost

Give the new mattermost user full access to the Mattermost server software.

sudo chown -R mattermost:mattermost /opt/mattermost

sudo chmod -R g+w /opt/mattermost

The user is set up. Now you must tell Mattermost what database the server should use. In the terminal window, open the following file with Nano.

sudo nano /opt/mattermost/config/config.json

Find this code in the file:

"mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"

Delete the code above from the configuration file and replace it with the code listed below.

Note: you must change mmuser-password with the mmuser SQL password you set earlier. You must also add in your servers hostname or IP address in host-name-or-IP.

"mmuser:<mmuser-password>@tcp(<host-name-or-IP>:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"

With all the edits made, it’s time to start up Mattermost to test it and make sure it runs correctly.

cd /opt/mattermost

sudo -u mattermost ./bin/mattermost

If the server runs correctly, close it by pressing Ctrl + C.

Create Mattermost systemd service

For Mattermost to run without any interaction with the user, a systemd service file is necessary. In the terminal, use the touch command and make a new systemd service.

sudo touch /lib/systemd/system/mattermost.service

Open up the new service file in Nano.

sudo nano /lib/systemd/system/mattermost.service

Paste the code below into Nano.

[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mysql.service

[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152

[Install]
WantedBy=mysql.service

Save the edits by pressing Ctrl + O, and exit by pressing Ctrl + X. Then, load up the new Mattermost systemd service.

sudo systemctl daemon-reload

sudo systemctl start mattermost.service

sudo systemctl enable mattermost.service

Access Mattermost

The Mattermost server is up and running. Access it and start using the service by visiting the following URL.

https://localhost:8065

Alternatively, follow our guide to get Snap packages working. Then, install Mattermost desktop with the command below.

sudo snap install mattermost-desktopĀ 

Comments are closed.