How To Install Mattermost on CentOS 7

Mattermost on CentOS 7

Mattermost is an open source, private cloud Slack-alternative. A workplace messaging system for web, PCs and phones, released under the MIT license.

As an alternative to proprietary SaaS messaging, Mattermost brings all your team communication into one place, making it searchable and accessible anywhere. Mattermost is “Slack-compatible, not Slack-limited”, supporting a superset of Slack’s incoming and outgoing webhook integrations, including compatibility with existing Slack integrations. From your existing Slack teams, you can import users, public channel history and even theme setting colors into Mattermost.

Prerequisites

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Mattermost on a CentOS 7 server.
Install Mattermost on CentOS 7

Step 1. First let’s start by ensuring your system is up-to-date.

yum clean all
yum -y update

Step 2. Installing MySQL database.

Install and set up the database for use by the Mattermost server. You can install MySQL using command below:

wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum localinstall mysql57-community-release-el7-9.noarch.rpm

Next, install MySQL:

sudo yum install mysql-community-server

Start the MySQL server:

systemctl start mysqld.service
chkconfig mysqld on

Configuring MySQL for SugarCRM.

By default, MySQL is not hardened. You can secure MySQL using the mysql_secure_installation script. you should read and below each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- 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

Next we will need to log in to the MySQL console and create a database for the Mattermost. Run the following command:

mysql -u root -p

This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Mattermost installation:

mysql> CREATE USER 'mmuser'@'localhost' IDENTIFIED BY 'mmuser_strong_password';
mysql> CREATE DATABASE mattermostdb;
mysql> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mmuser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Step 3. Installing Mattermost Server.

First thing to do is to go to Mattermost’s download page and download the latest stable version of Mattermost, At the moment of writing this article it is version 3.6.2:

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

Unpack the Mattermost archive to the document root directory on your server:

tar xf *.gz
mv mattermost /opt/

Create the storage directory for files:

mkdir /opt/mattermost/data

Set up a system user and group called mattermost that will run this service, and set the ownership and permissions:

useradd --system --user-group mattermost
chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost

Set up the database driver through the /opt/mattermost/config/config.json file. In it, search for “DriverName” and “DataSource” lines and change as follows:

"DriverName": "mysql"
"DataSource": "mmuser:@tcp(localhost:3306)/mattermost?charset=utf8"

Save, exit, and test the Mattermost Server with the following command:

sudo -u mattermost /opt/mattermost/bin/platform

When the server starts, it shows some log information and the text Server is listening on :8065. You can stop the server by pressing CTRL+C in the terminal window.

Step 4. Create a systemd unit for Mattermost.

Create a systemd file for Mattermost, /etc/systemd/system/mattermost.service and, in it, paste the following configuration:

[Unit]
Description=Mattermost
After=syslog.target network.target postgresql-9.4.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

Make the service executable:

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

And reload the services:

systemctl daemon-reload

Enable Mattermost service:

chkconfig mattermost on

And start it with systemd:

systemctl start mattermost

Step 5. Installing and configure NGINX.

In a production system, use a proxy server in front of Mattermost Server. In this case, NGINX. The main benefits of doing this are:

SSL termination
Port mapping :80 to :8065
HTTP to HTTPS redirect
Standard request logs

In order to install NGINX on CentOS 7, create a yum repository file, /etc/yum.repos.d/nginx.repo, with the following content:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/7.1/$basearch/
gpgcheck=0
enabled=1

Install Nginx using YUM command:

yum install nginx.x86_64

After the installation is complete, start NGINX:

systemctl start nginx
systemctl enable nginx

Configuration Nginx.

In order to configure NGINX as proxy server, create the file /etc/nginx/sites-available/mattermost and past:

upstream backend {
server localhost:8065;
}

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.mydomain.com;

location /api/v3/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;
proxy_read_timeout 600s;
proxy_pass http://backend;
}

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_pass http://backend;
}
}

Remove the existing default sites-enabled file:

rm /etc/nginx/sites-enabled/default

Enable the mattermost configuration:

ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost

Finally, restart Nginx service:

systemctl restart nginx

Step 7. Accessing Mattermost.

Mattermost will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://mattermost.mydomain.com/ and continue to configure Mattermost by entering an email address and creating an account. If you are using a firewall, please open port 80 to enable access to the control panel.

Congratulation’s! You have successfully installed Mattermost. Thanks for using this tutorial for installing Mattermost on CentOS 7 system. For additional help or useful information, we recommend you to check the official Mattermost web site.

How To Install Mattermost 5.10.0 on Ubuntu 18.04 LTS

Install Mattermost on Ubuntu 18

Mattermost is an open source, private cloud Slack-alternative. A workplace messaging system for web, PCs and phones, released under the MIT license.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Mattermost on a Ubuntu 18.04 LTS (Bionic Beaver) server.

Install Mattermost on Ubuntu 18.04

Step 1. First make sure that all your system packages are up-to-date

sudo apt-get update
sudo apt-get upgrade

Step 2. Install LAMP (Linux, Apache, MariaDB and PHP) server.

A Ubuntu 18.04 LAMP server is required. If you do not have LAMP installed, you can follow our guide here. Also install all required PHP modules:

apt-get install php7.1-cli php7.1-gd php7.1-opcache php7.1-mysql php7.1-json php7.1-mcrypt php7.1-xml php7.1-curl

Step 3. Installing Mattermost Server on Ubuntu 18.04 LTS.

First thing to do is to go to Mattermost’s download page and download the latest stable version of Mattermost, At the moment of writing this article it is version 5.1.0:

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

Unpack the Mattermost archive to the document root directory on your server:

tar -xvzf mattermost*.gz
sudo mv mattermost /opt

Next, create a storage directory for file:

sudo mkdir /opt/mattermost/data

Set up a system user and group called mattermost that will run this service, and set the ownership and permissions:

sudo useradd --system --user-group mattermost
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost

Set up the database driver through the /opt/mattermost/config/config.json file. In it, search for “DriverName” and “DataSource” lines and change as follows:

"DriverName": "mysql"
"DataSource": "mattermostuser:new_password_here@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=$""

Step 4. Create a systemd unit for Mattermost.

Create a systemd file for Mattermost, /etc/systemd/system/mattermost.service and, in it, paste the following configuration:

nano /etc/systemd/system/mattermost.service

Add following content:

[Unit]
Description=Mattermost
After=network.target
After=mariadb.service
Requires=mariadb.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=mariadb.service

Next, run the commands below to start Mattermost service:

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

Step 7. Accessing Mattermost.

Mattermost will be available on HTTP port 8065 by default. Open your favorite browser and navigate to http://your-domain.com:8065 or http://ip-address:8065 and continue to configure Mattermost by entering an email address and creating an account. If you are using a firewall, please open port 8065 to enable access to the control panel.

Congratulation’s! You have successfully installed Mattermost. Thanks for using this tutorial for installing Mattermost on your Ubuntu 18.04 LTS (Bionic Beaver) system. For additional help or useful information, we recommend you to check the official Mattermost web site.