Mattermost is an open-source and self-hosted chat server written in Golang and React. It's very similar to Slack and offers a chat service with file sharing, search, and integrations. It helps teams to communicate with each other from everywhere over the internet.
Features
- Client apps are available for iOS, Android, Windows, Mac, Linux.
- Supports multi-factor authentication.
- Contains threaded messaging, emoji, and custom emoji.
- Supports customizing and branding.
- One-to-one and group messaging are available.
- Includes unlimited search history.
In this guide, you'll learn how to install the Mattermost Chat server on Ubuntu 20.04.
Prerequisites
- A server running on Ubuntu 20.04.
- A root password configured on your server.
Install and Configure MariaDB
First of all, install the MariaDB server using the following command:
# apt-get install mariadb-server -y
Next, log in to MariaDB with the following command:
# mysql
After login, create a database and user using the following command:
# MariaDB [(none)]> CREATE DATABASE mattermost;
# MariaDB [(none)]> CREATE USER 'mattermost'@'%' IDENTIFIED BY 'password';
Next, grant all the privileges to Mattermost with the following command:
# MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermost.* TO 'mattermost'@'%';
Next, flush the privileges and exit from the MariaDB with the following command:
# MariaDB [(none)]> FLUSH PRIVILEGES;
# MariaDB [(none)]> EXIT;
Install Mattermost
First, create a separate user for Mattermost with the following command:
# useradd --system --user-group mattermost
Next, download the latest version of Mattermost with the following command:
# wget https://releases.mattermost.com/5.36.1/mattermost-5.36.1-linux-amd64.tar.gz
Once the download is completed, extract the downloaded file with the following command:
# tar -xzf mattermost-5.36.1-linux-amd64.tar.gz
Next, move the extracted directory to /opt:
# mv mattermost /opt/
Next, create a data directory for Mattermost:
# mkdir /opt/mattermost/data
Next, set proper permission and ownership with the following command:
# chown -R mattermost:mattermost /opt/mattermost
# chmod -R g+w /opt/mattermost
Next, edit the Mattermost confiugration file:
# nano /opt/mattermost/config/config.json
Define your site URL as shown below:
#"SiteURL": "http://mattermost.example.com",
Next, find the following lines:
# "DriverName": "postgres",
# "DataSource": "postgres://mmuser:mostest@localhost/mattermost_test?sslmode=disable\u0026connect_timeout=10",
And replace them by the following lines:
# "DriverName": "mysql",
# "DataSource": "mattermost:password@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",
Save and close the file.
Create a Systemd Service File
Next, you'll need to create a systemd service file for Mattermost. You can create it with the following command:
# nano /lib/systemd/system/mattermost.service
Add the following lines:
[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mysql.service
[Service]
Type=notify
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
LimitNOFILE=49152
[Install]
WantedBy=mariadb.service
Save and close the file then reload the systemd daemon:
# systemctl daemon-reload
Next, start the Mattermost service and enable it to start at system reboot:
# systemctl start mattermost
# systemctl enable mattermost
Configure Nginx as a Reverse Proxy
Next, install the Nginx server with the following command:
# apt-get install nginx -y
Once installed, create an Nginx virtual host configuration file:
# nano /etc/nginx/conf.d/mattermost.conf
Add the following lines:
upstream mattermost {
server localhost:8065;
keepalive 32;
}
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;
server {
listen 80;
server_name mattermost.example.com;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 50M;
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_buffers 256 16k;
proxy_buffer_size 16k;
client_body_timeout 60;
send_timeout 300;
lingering_timeout 5;
proxy_connect_timeout 90;
proxy_send_timeout 300;
proxy_read_timeout 90s;
proxy_pass http://mattermost;
}
location / {
client_max_body_size 50M;
proxy_set_header Connection "";
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_buffers 256 16k;
proxy_buffer_size 16k;
proxy_read_timeout 600s;
proxy_cache mattermost_cache;
proxy_cache_revalidate on;
proxy_cache_min_uses 2;
proxy_cache_use_stale timeout;
proxy_cache_lock on;
proxy_http_version 1.1;
proxy_pass http://mattermost;
}
}
Save and close the file then restart the Nginx service to apply the changes:
# systemctl restart nginx
Access Mattermost
Now, you can access the Mattermost using the URL http://mattermost.example.com. You should see the following screen:
Provide your email, admin username, password and click on the "Create Account". You should see the following screen:
Click on "Create a team" button. You should see the following screen:
Provide your team name and click on "Next" button. You should see the following screen:
Define your team URL and click on the "Finish" button. You will be redirected to the Mattermost dashboard:
Conclusion
You can now implement the Mattermost chat in your organization and used it as an internal chat platform!