How To Install Mattermost on Ubuntu 18.04 LTS

How To Install Mattermost on Ubuntu 18.04 LTS

Introduction

Mattermost is an open-source platform that is written in React and Golang. It can be used as an alternative messaging platform and utilizes the PostgreSQL or MySQL database in the backend. Mattermost main function is to bring team communication together and offer several features such as file sharing, custom emojis, video calls, messaging (one-on-one or group), and so on.

In this guide, we will take you the process of installing Mattermost on an Ubuntu 18.04 server. We will also configure Nginx as an SSL reverse proxy.

Prerequisites

Before you begin, make sure you have the following:

  • A domain name that points to your server IP address
  • A non-root user with sudo privileges
  • Fully installed Nginx
  • A fully installed SSL certificate for your domain.

Step 1 –
Creating MySQL Database

Start by installing the MySQL database for Mattermost.

Begin by logging into the MySQL shell:

$ sudo mysql -u root

Next, create a new MySQL database and user for the sake of Mattermost installation. To do, run the command below:

CREATEDATABASE mattermost;
GRANT ALL ON mattermost.* TO mattermost@localhost IDENTIFIEDBY'Password';

Note: You can create a more secure password of your choice for the ‘password’ section.

Step 2 –
Creating a new user

Now, create a new system user and group for the sake of Mattermost instance. In this case, we will name our user mattermost:

$ sudo useradd -U -M -d /opt/mattermost mattermost

Once you have created a user, go ahead and install Mattermost to your server.

Step 3 –
Installing Mattermost Server

To download the latest stable Mattermost version, type:

$ sudo curl -L https://releases.mattermost.com/5.1.0/mattermost-5.1.0-linux-amd64.tar.gz -o /tmp/mattermost.tar.gz

Once the file is downloaded, extract it and transfer it to /opt directory:

$ sudo tar zxf /tmp/mattermost.tar.gz -C /opt

Next, create a storage directory for these files:

$ sudo mkdir -p /opt/mattermost/data

Make sure you change the ownership of the directory to the mattermost user:

$ sudo chown -R mattermost: /opt/mattermost

Go to the >/opt/mattermost/config/config.json file, and set the database to MySQL then fill the database details:

/opt/mattermost/config/config.json

"SqlSettings": {
    "DriverName": "mysql",
    "DataSource": "mattermost:P4ssvv0rD@tcp(localhost:3306)/mattermost?charset=utf8,utf8&readTimeout=30s&writeTimeout=30s",

Now, we need to test whether the Mattermost server is working properly. To do so, change into the /opt/mattermost directory then run the command below to start the server:

$cd /opt/mattermost
$ sudo -u mattermost bin/mattermost

If the server is working properly, your server should start immediately and you should see the output below:

{"level":"info","ts":1532546921.941638,"caller":"app/server.go:115","msg":"Starting Server..."}
{"level":"info","ts":1532546921.9421031,"caller":"app/server.go:154","msg":"Server is listening on [::]:8065"}
{"level":"info","ts":1532546921.9541554,"caller":"app/web_hub.go:75","msg":"Starting 2 websocket hubs"}

Now, you can halt the Mattermost server by clicking the combination keys CTRL+Cand proceed to the next step.

Step 4 –
Creating a Systemd Unit

To successfully run Mattermost as a service, create a unit file known as mattermost.service in the /etc/systemd/system/ directory.

Open the text file and create the file below:

/etc/systemd/system/mattermost.service

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

Now, inform systemd that a new unit file has been created then restart the Mattermost service using the commands below:

$ sudo systemctl daemon-reload
$ sudo systemctl start mattermost

Check to confirm the status of the service with the command below:

$ sudo systemctl status mattermost

The output should look like this:

● mattermost.service - Mattermost
   Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; ven
   Active: active (running) since Wed 2018-08-2518:39:05 UTC; 41s ago
 Main PID: 3091 (mattermost)
    Tasks: 18 (limit: 507)
   CGroup: /system.slice/mattermost.service
           ├─3091/opt/mattermost/bin/mattermost

If this command doesn’t present any errors, set the Mattermost service to start at boot time:

$ sudo systemctl enable mattermost

Step 5 –
Setting up a reverse proxy using Nginx

This tutorial assumes that you have already installed NGINX and configured it with SSL certificate.

Now, create a server block for Mattermost. Open your editor and create the file below:

/etc/nginx/conf.d/example.com.conf

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;
upstream mattermost_backend {
  server127.0.0.1:8065;
}
server {
    listen80;
    server_name example.com www.example.com;
    include snippets/letsencrypt.conf;
    return301 https://example.com$request_uri;
}
server {
    listen443 ssl http2;
    server_name www.example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    return301 https://example.com$request_uri;
}
server {
    listen443 ssl http2;
    server_name example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/example.com-error.log;
    location~ /api/v[0-9]+/(users/)?websocket$ {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size50M;
       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_buffers25616k;
       proxy_buffer_size16k;
       proxy_read_timeout600s;
       proxy_pass http://mattermost_backend;
    }
    location / {
       proxy_http_version1.1;
       client_max_body_size50M;
       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_buffers25616k;
       proxy_buffer_size16k;
       proxy_read_timeout600s;
       proxy_cache mattermost_cache;
       proxy_cache_revalidateon;
       proxy_cache_min_uses2;
       proxy_cache_use_stale timeout;
       proxy_cache_lockon;
       proxy_pass http://mattermost_backend;
    }
}

Restart the Nginx server to apply these changes:

$ sudo systemctl reload nginx

Step 6 –
Configuring the Mattermost Service

To configure Mattermost service, go to your browser and enter the domain name where you will be directed to the signup page.

Type your email, username, and password, then press the Create Account button to complete the process and create your account.

How To Install Mattermost on Ubuntu 18

The first user in your system should have administrator privileges.

Next, you will be prompted to create a new team.

How To Install Mattermost on Ubuntu 18

Click the link Create a new team, then type the name of your team then press the Next button.

How To Install Mattermost on Ubuntu 18

Now, you will be prompted to select a web for your new team.

How To Install Mattermost on Ubuntu 18

Press the Finish button. You will be directed to the Mattermost web interface. Log in as the administrator.

How To Install Mattermost on Ubuntu 18

Locate the System Console and open it, click on the username and a new menu will open. Click the link System Console.

Enter the site URL by navigating to the Settings General area and click Configuration.

How To Install Mattermost on Ubuntu 18

To ensure the email notifications is enabled, navigate to the Notifications icon, click Email, then change the Enable Email Notifications section from false to true and also enter the SMTP parameters.

How To Install Mattermost on Ubuntu 18

You can also use other popular email services including Amazon SES, SendinBlue, Postmark, Mailgun, SendGrid, Mailjet, and Mandrill.

The last step is to restart the Mattermost service to apply these changes:

$ sudo systemctl restart mattermost

Conclusion

Congratulations! Now the Mattermost service is installed successfully on your Ubuntu 18.04 server. You have also set up Nginx as a reverse proxy, and you can start enjoying Mattermost services and work together with your team.

Check out these top 3 VPS services:

Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
Liquid Web
$5.00 /mo
Starting price
Visit Liquid Web
Rating based on expert review
  • User Friendly
    3.8
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.6
  • Pricing
    3.8

How to Create a Non-root User on Your Ubuntu 18.04 VPS or Dedicated Server

This guide shows you how to create a user on your Ubuntu 18.04 virtual server.
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Install a Self-Signed SSL Certificate on Your Ubuntu 18.04 VPS or Dedicated Server

This how-to article will teach you how to create a self-signed SSL certificate o
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Set Up Cron Jobs on Your Ubuntu 18.04 Dedicated Server or VPS

This guide shows webmasters and administrators how to set up cron jobs on your U
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install WordPress on Your Ubuntu 22.04 VPS or Dedicated Server

This tutorial will show you how to install WordPress on your Ubuntu 22.04 virtua
3 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top