How to Install Mattermost 4.1 on CentOS 7

Updated on December 15, 2017
How to Install Mattermost 4.1 on CentOS 7 header image

Mattermost is an open source, self-hosted alternative to the Slack SAAS messaging service. In other words, with Mattermost, you can setup a private and dedicated messaging server on your own machine for your team.

Prerequisites

  • A newly created Vultr CentOS 7 x64 server instance. Say its IP address is 203.0.113.1.
  • A sudo user.
  • The server instance has been updated to the latest stable status using the EPEL YUM repo.
  • A domain mattermost.example.com that has been configured to point to the 203.0.113.1 server instance. You can learn more details about this in another Vultr tutorial.
  • In order to automatically obtain the Let's Encrypt certificate, the server instance's FQDN should have been configured as mattermost.example.com.

Step 1: Install and configure MariaDB 10.2

As required by Mattermost, you need to setup a database to store all the data for Mattermost. For that purpose, we will install MariaDB.

#####Use the following commands to install MariaDB 10.2.

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum install MariaDB-server MariaDB-client -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

#####Secure MariaDB 10.2

sudo /usr/bin/mysql_secure_installation

When prompted, answer the questions.

  • Enter current password for root (enter for none): Just press the Enter button
  • Set root password? [Y/n]: Y
  • New password: your-MariaDB-root-password
  • Re-enter new password: your-MariaDB-root-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

#####Create a MariaDB database for Mattermost.

Log into the MariaDB shell as root.

mysql -u root -p

In the MariaDB shell, input the following statements.

Note: For security purposes, be sure to replace mattermost, mattermostuser, and yourpassword with your own ones.

CREATE DATABASE mattermost;
CREATE USER 'mattermostuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON mattermost.* TO 'mattermostuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 2: Install and configure Mattermost

Download and extract the Mattermost 4.1 archive.

cd
wget https://releases.mattermost.com/4.1.0/mattermost-4.1.0-linux-amd64.tar.gz
tar -zxvf mattermost-4.1.0-linux-amd64.tar.gz

Move all Mattermost files to the /opt directory, and then create a subdirectory /opt/mattermost/data to store program data.

sudo mv ~/mattermost /opt
sudo mkdir /opt/mattermost/data

Create a dedicated user mattermost and a dedicated group mattermost for running Mattermost.

sudo useradd --system --user-group mattermost

Modify all Mattermost program files' ownership and permissions.

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

In order to setup an HTTPS-enabled Mattermost server, you need to make modifications to the Mattermost config file.

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

Find these lines, one by one.

"SiteURL": "",
"ListenAddress": ":8065",
"ConnectionSecurity": "",
"UseLetsEncrypt": false,
"Forward80To443": false,
"DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",

Replace them with the lines below.

"SiteURL": "https://mattermost.example.com",
"ListenAddress": ":443",
"ConnectionSecurity": "TLS",
"UseLetsEncrypt": true,
"Forward80To443": true,
"DataSource": "mattermostuser:yourpassword@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",

Note: In the DataSource line, you need to sequentially specify the database username mattermostuser, the corresponding password yourpassword, the database server location localhost, and the database name mattermost.

Make sure that the DriverName line above the DataSource line is using the default value mysql.

"DriverName": "mysql",

Save and quit.

:wq!

Allow Mattermost to bind to privileged ports, i.e. 80 and 443.

cd /opt/mattermost/bin
sudo setcap cap_net_bind_service=+ep ./platform

Manage Mattermost with systemd.

Create a Mattermost systemd unit file.

cat <<EOF | sudo tee -a /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost
After=syslog.target network.target mysqld.service

[Service]
Type=simple
WorkingDirectory=/opt/mattermost/bin
User=mattermost
ExecStart=/opt/mattermost/bin/platform
PIDFile=/var/spool/mattermost/pid/master.pid
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target
EOF

Modify permissions on this systemd unit file.

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

Start the Mattermost service and make it automatically start on system boot.

sudo systemctl daemon-reload
sudo systemctl start mattermost.service
sudo systemctl enable mattermost.service

Allow access on the http and https ports.

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload

Finally, point your favorite web browser to http://mattermost.example.com or https://mattermost.example.com, and you will see the Mattermost Sign Up page.

On the Mattermost Sign Up page, input an email address, a username, and a password, and then click the Create Account button to register the first user.

Note: Be aware that the first user you register will also be the system administrator.

On the Team Name page and the Team URL page, input a team name and a URL for your first team.

You have now successfully setup a Mattermost messaging server which is robust enough to serve a small- or mid-sized team in production environment. Feel free to explore the interface of Mattermost and invite more team members.