How To Install Mattermost on Ubuntu 18.04 LTS

How To Install Mattermost on Ubuntu 18.04 LTS

Introduction

[openingText]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.[/openingText]

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:

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

Step 1 –
[stepName]Creating MySQL Database[/stepName]

[step]

Start by installing the MySQL database for Mattermost.

[howToDirection]

Begin by logging into the MySQL shell:

$ sudo mysql -u root

[/howToDirection]

[howToDirection]

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.

[/howToDirection]

[/step]

Step 2 –
[stepName]Creating a new user[/stepName]

[step]

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]

Step 3 –
[stepName]Installing Mattermost Server[/stepName]

[step]

[howToDirection]

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

[/howToDirection]

[howToDirection]

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

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

[/howToDirection]

[howToDirection]

Next, create a storage directory for these files:

$ sudo mkdir -p /opt/mattermost/data

[/howToDirection]

[howToDirection]

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

$ sudo chown -R mattermost: /opt/mattermost

[/howToDirection]

[howToDirection]

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=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",

[/howToDirection]

[howToDirection]

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

[/howToDirection]

[howToDirection]

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.

[/howToDirection]

[/step]

Step 4 –
[stepName]Creating a Systemd Unit[/stepName]

[step]

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

[howToDirection]

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

[/howToDirection]

[howToDirection]

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

[/howToDirection]

[howToDirection]

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

$ sudo systemctl status mattermost

[/howToDirection]

[howToDirection]

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

[/howToDirection]

[howToDirection]

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

$ sudo systemctl enable mattermost

[/howToDirection][/step]

Step 5 –
[stepName]Setting up a reverse proxy using Nginx[/stepName]

[step]

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

[howToDirection]

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;
    }
}

[/howToDirection]

[howToDirection]

Restart the Nginx server to apply these changes:

$ sudo systemctl reload nginx

[/howToDirection][/step]

Step 6 –
[stepName]Configuring the Mattermost Service[/stepName]

[step]

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

[howToDirection]

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

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

The first user in your system should have administrator privileges.

[howToDirection]

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

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

[howToDirection]

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

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

[howToDirection]

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

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

[howToDirection]

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

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

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

[howToDirection]

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

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

[howToDirection]

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.

[stepImage]How To Install Mattermost on Ubuntu 18[/stepImage]

[/howToDirection]

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

[howToDirection]

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

$ sudo systemctl restart mattermost

 

[/howToDirection][/step]

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:

Hostinger
MYR 6.35 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.9
  • Support
    4.9
  • Features
    4.8
  • Reliability
    4.7
  • Pricing
    4.5
Kamatera
MYR 15.98 /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
Hosting.com
MYR 11.95 /mo
Starting price
Visit Hosting.com
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0

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.
less than a minute
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
less than a minute
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
less than a minute
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
less than a minute
Idan Cohen
Idan Cohen
Marketing Expert
Click to go to the top of the page
Go To Top
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.