Deploy the Mattermost server. Install Mattermost on Ubuntu using PostgreSQL and Nginx. A privacy alternative for slack.

Communication is the most important aspect of the team’s success. Having efficient communication with the team members has to be a key component for any team leader. This key component in today’s corporate environment is dominated by Instant messaging tools like slack and discord. This wasn’t the case before, instead the use of email was considered for team communication. But the biggest difference between the emails and instant messaging is speed. Humans have become more impatient, getting an instant reply is a must to maintain efficiency within teammates.

Privacy is a concern for many companies handling sensitive data. And to resolve this issue most companies prefer the data to be processed and handled on-premise. For which free and open-source can be the best option for self-hosting as per the company’s requirement towards privacy.

Mattermost is an open-source, self-hosted chat service. It is marketed as a slack alternative for the privacy-conscious enterprise. To see the comparative click the link: https://mattermost.com/mattermost-vs-slack/

But let’s get started with the installation of the Mattermost server on the Ubuntu server using PostgreSQL and Nginx.

  1. Let’s install the required packages
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install software-properties-common wget -y

2. Now install and configure PostgreSQL.

sudo apt-get install postgresql postgresql-contrib

sudo su - postgres

psql


\password postgres

CREATE DATABASE matterdb;

CREATE USER matteruser WITH PASSWORD 'Password';

GRANT ALL PRIVILEGES ON DATABASE matterdb TO matteruser;

\q


exit

3. Installation and Configuration of the Mattermost

sudo useradd -m -s /bin/bash matter
sudo passwd matter
sudo su - matter
wget https://releases.mattermost.com/5.25.0/mattermost-5.25.0-linux-amd64.tar.gz
tar -xzvf mattermost-5.25.0-linux-amd64.tar.gz
cd mattermost/
mkdir data/

4. Edit database credential for Mattermost

nano config/config.json

5. Change as following and save the file

"DriverName": "postgres",
"DataSource": "postgres://matteruser:Password@127.0.0.1:5432/matterdb?sslmode=disable&connect_timeout=10",

6. Configure Mattermost as service

cd bin/
./platform
ctrl^c
exit
cd /etc/systemd/system/
nano mattermost.service

7. Add following lines

[Unit]
Description=Mattermost
After=syslog.target network.target postgresql-9.4.service

[Service]
Type=simple
User=matter
Group=matter
ExecStart=/home/matter/mattermost/bin/platform
PrivateTmp=yes
WorkingDirectory=/home/matter/mattermost
Restart=always
RestartSec=30
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

8. Reload Mattermost service and check status

systemctl daemon-reload ; systemctl start mattermost
netstat -plntu
systemctl status mattermost

9. Now let’s install and configure nginx

sudo apt install nginx -y
cd /etc/nginx/
mkdir ssl/ ; cd ssl/
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/ssl/mattermost.crt -keyout /etc/nginx/ssl/mattermost.key
chmod 400 mattermost.key
cd /etc/nginx/sites-available/
nano mattermost

10. Add following lines in the file

server {
        listen 80;
        server_name    mattermost.yoursite.com;
        return 301 https://$server_name$request_uri;
}

server {
        listen 443 ssl;
        server_name mattermost.yoursite.com;

        ssl on;
        ssl_certificate /etc/nginx/ssl/mattermost.crt;
        ssl_certificate_key /etc/nginx/ssl/mattermost.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-$        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;

        location / {
                gzip off;
                proxy_set_header X-Forwarded-Ssl on;
                client_max_body_size 50M;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
		proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Frame-Options SAMEORIGIN;
                proxy_pass http://127.0.0.1:8065;
        }
}

11. Test the Configuration and make symlink

nginx -t
ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
nginx -t
sudo systemctl restart nginx
sudo systemctl enable mattermost
sudo systemctl restart mattermost

You have to set up your DNS to point to mattermost.yoursite.com and enter that URL to your browser and follow first-time setup instructions shown on screen.

Use the last URL in credits and useful link to get lets-encrypt certificate installed. It is an straightforward process.

Credits and useful links :
https://www.youtube.com/watch?v=3MFnXjlNmOc
https://docs.mattermost.com/install/install-ubuntu-1804.html
https://docs.mattermost.com/install/config-ssl-http2-nginx.html
https://mattermost.com/mattermost-vs-slack/
https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx

Leave a Comment