Mattermost is a free, open-source, and secure platform for communication, collaboration, and workflow orchestration across tools and teams. It is a self-hosted chat service designed for organizations and companies to implement an internal chat service. It offers several useful features including one-to-one messaging, unlimited search history, file sharing, two-factor authentication, notifications, and more. If you are looking for an alternate solution for Slack then Mattermost is the best choice for you.

In this tutorial, we will show you how to install Mattermost with Nginx on Alma Linux 8.

Prerequisites

  • A server running Alma Linux 8.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Install MySQL Server

Mattermost uses MySQL as a database backend. So MySQL must be installed on your server. You can install it by running the following command:

dnf install mysql-server -y

Once the MySQL server is installed, start and enable the MySQL service with the following command:

systemctl start mysqld

systemctl enable mysqld

Now, you can secure the MySQL installation by running the following script:

mysql_secure_installation

Answer all the questions as shown below to set the MySQL root password and secure the installation:

Press y|Y for Yes, any other key for No: N
Please set the password for root here.
New password: 
Re-enter new password: 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Create a Database for Mattermost

Next, you will need to create a database and user for Mattermost. First, log in to MySQL with the following command:

mysql -u root -p

Once you are log in, create a database and user with the following command:

mysql> CREATE DATABASE matterdb;

mysql> CREATE USER 'matteruser'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the Mattermost database:

mysql> GRANT ALL PRIVILEGES ON matterdb.* TO [email protected];

Next, flush the privileges and exit from the MySQL with the following command:

mysql> FLUSH PRIVILEGES;

mysql> EXIT;

Once you are finished, you can proceed to the next step.

Install Mattermost on Alma Linux 8

First, create a dedicated user to run Mattermost using the following command:

useradd --system --user-group mattermost

Next, download the latest version of Mattermost using the following command:

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

Once the download is completed, extract the downloaded file with the following command:

tar -xf mattermost-6.0.2-linux-amd64.tar.gz

Next, move the extracted directory to the /opt:

mv mattermost /opt

Next, create a data directory for Mattermost and change the ownership and permission of the Mattermost:

mkdir /opt/mattermost/data

chown -R mattermost:mattermost /opt/mattermost

chmod -R g w /opt/mattermost

Next, edit the Mattermost configuration file:

nano /opt/mattermost/config/config.json

Define your Mattermost website URL as shown below:

    "SiteURL": "http://mattermost.example.com",

Next, find the following lines:

    "DriverName": "postgres",
    "DataSource": "postgres://mmuser:[email protected]/mattermost_test?sslmode=disableu0026connect_timeout=10",

And, replaced them with the following lines:

    "DriverName": "mysql",
    "DataSource": "matteruser:[email protected](localhost:3306)/matterdb?charset=utf8mb4,utf8u0026readTimeout=30su0026writeTimeout=30s",

Save and close the file when you are finished.

Create a Systemd Service File for Mattermost

Next, you will need to create a systemd service file to manage the Mattermost service. You can create it by running the following command:

nano /etc/systemd/system/mattermost.service

Add the following lines:

[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
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

Save and close the file then reload the systemd daemon with the following command:

systemctl daemon-reload

Next, start the Mattermost service and enable it to start at system reboot:

systemctl start mattermost

systemctl enable mattermost

You can now check the status of the Mattermost service with the following command:

systemctl status mattermost

You will get the following output:

? mattermost.service - Mattermost
   Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-15 14:12:29 UTC; 7s ago
 Main PID: 15201 (mattermost)
    Tasks: 32 (limit: 11411)
   Memory: 265.2M
   CGroup: /system.slice/mattermost.service
           ??15201 /opt/mattermost/bin/mattermost
           ??15298 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
           ??15299 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
           ??15308 plugins/playbooks/server/dist/plugin-linux-amd64
           ??15313 plugins/focalboard/server/dist/plugin-linux-amd64

Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.344 Z","level":"info","msg":"Sent notification of next survey>
Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.402 Z","level":"info","msg":"Post.Message has size restrictio>
Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.499 Z","level":"info","msg":"info [2022-01-15 14:12:26.497 Z]>
Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.537 Z","level":"info","msg":"n    -- collation of mattermost>
Jan 15 14:12:28 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:28.297 Z","level":"info","msg":"debug [2022-01-15 14:12:28.295 Z>
Jan 15 14:12:28 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:28.804 Z","level":"info","msg":"info [2022-01-15 14:12:28.803 Z]>
Jan 15 14:12:29 almalinux8 systemd[1]: Started Mattermost.
Jan 15 14:12:29 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:29.149 Z","level":"info","msg":"Starting Server...","caller":"ap>
Jan 15 14:12:29 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:29.150 Z","level":"info","msg":"Server is listening on [::]:8065>
Jan 15 14:12:29 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:29.150 Z","level":"info","msg":"Sending systemd READY notificati>

At this point, Mattermost is started and running on port 8065. You can check it with the following command:

ss -antpl | grep 8065

You will get the following output:

LISTEN 0      128                *:8065             *:*    users:(("mattermost",pid=15201,fd=35))                   

Once you are finished, you can proceed to the next step.

Configure Nginx as a Reverse Proxy for Mattermost

It is recommended to install and configure Nginx as a reverse proxy for Mattermost. To do so, you will need to install the Nginx server to your server. You can install it by running the following command:

dnf install nginx -y

Once the Nginx has been installed, create an Nginx virtual host configuration file with the following command:

nano /etc/nginx/conf.d/mattermost.conf

Add the following lines:

 server {
        listen       80;
        server_name  mattermost.example.com;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
	proxy_pass http://localhost:8065/;
            index  index.html index.htm;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

Save and close the file then verify the Nginx for any configuration error:

nginx -t

If everything is fine, you will get the following output:Advertisement

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now, start and enable the Nginx service to start at system reboot:

systemctl start nginx

systemctl enable nginx

You can check the status of the Nginx using the following command:

systemctl status nginx

You will get the following output:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-15 14:14:05 UTC; 7s ago
  Process: 15356 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 15354 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 15351 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 15358 (nginx)
    Tasks: 2 (limit: 11411)
   Memory: 3.8M
   CGroup: /system.slice/nginx.service
           ??15358 nginx: master process /usr/sbin/nginx
           ??15359 nginx: worker process

Jan 15 14:14:05 almalinux8 systemd[1]: nginx.service: Succeeded.
Jan 15 14:14:05 almalinux8 systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Jan 15 14:14:05 almalinux8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 15 14:14:05 almalinux8 nginx[15354]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 15 14:14:05 almalinux8 nginx[15354]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 15 14:14:05 almalinux8 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jan 15 14:14:05 almalinux8 systemd[1]: Started The nginx HTTP and reverse proxy server.

At this point, Nginx is installed and configured to serve Mattermost. You can now proceed to the next step.

Configure Firewall

Next, you will need to allow port 80 through the firewall. You can allow it by running the following command:

firewall-cmd --add-service=http --permanent

Next, reload the firewall to apply the changes:

firewall-cmd --reload

Once you are finished, you can proceed to the next step.

Access Mattermost Web UI

Now, open your web browser and access the Mattermost web interface using the URL http://mattermost.example.com. You will be redirected to the following screen:

<img alt="Mattermost sign-in form" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/p1.png61ea9e3fc5da0.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="539" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide your email address, admin username, password, and click on the Create Account button. You will get the following screen:

<img alt="Join team" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/p2.png61ea9e401f42d.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="390" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on Create a team. You will get the following screen:

<img alt="Set team name" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/p3.png61ea9e40443bf.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="359" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide your Team name and click on the Next button. You will get the following screen:

<img alt="Configure team url in mattermost" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/p4.png61ea9e406b3d7.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="423" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide your Mattermost team URL and click on the Finish button. You will get the Mattermost dashboard on the following screen:

<img alt="Mattermost dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/p5.png61ea9e4093907.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="388" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

In the above guide, you learned how to install Mattermost chat service with Nginx on Alma Linux 8. You can now implement Mattermost in your organization and start using it as an internal chat. Feel free to ask me if you have any questions.