How to Install Mattermost with PostgreSQL and Nginx on Ubuntu 16.04

A tutorial on how to install Mattermost with PostgreSQL and Nginx on Ubuntu 16.04. Mattermost is an open source messaging system written in the programming languages Golang and React. It’s a slack alternative, we can build our own messaging service like slack or hipchat with it. Mattermost brings your team communication to a single place and makes it accessible anywhere. You can access it from your desktop, Android device, and iPhone.

Prerequisite

  • Ubuntu 16.04 – 64bit
  • Root Privileges+

How to Install Mattermost with PostgreSQL and Nginx on Ubuntu 16.04

Step 1 – Install and Configure the PostgreSQL Database

Connect to your server by SSH or login on the terminal and update the Ubuntu repository.

As the root user, install PostgreSQL with this apt command.

When the installation finished, login to the postgres user and type in the command ‘psql‘ to login to the postgresql shell.

Change the postgres user password with the command below:

Next, we have to configure a new database and user for the Mattermost installation. I will create a new database named ‘mattermostdb‘ and user ‘matteruser‘ with password ‘matterpassword‘. Please chose a secure password for your installation.

Create the new database and user with PostgreSQL query below:

Grant ‘matteruser‘ privileges to the database ‘mattermostdb‘ and exit.

Step 2 – Install and Configure Mattermost

Create new ‘matter‘ user and password.

‘matter’ user created, now login to the user and download the latest Mattermost version with wget.

Extract the Mattermost file and you will see new directory ‘mattermost’, enter that directory with the cd command.

Next, create a new ‘data’ directory for storing the user files, then edit the mattermost config file ‘config/config.json‘ with vim.

We will run mattermost behind a Nginx reverse proxy, so it’s better to configure Mattermost to listen on the local IP address. In the ‘ServiceSettings‘ block, add the localhost IP address to the configuration on line 4.

Now go to the ‘SqlSettings‘ on line 48. Change the ‘DriverName‘ and ‘DataSource‘ configuration to use the PostgreSQL database with the configuration below:

 

**Note:_

_**

matteruser = postgresql user.

matterpassword = the password.

mattermostdb = the database.

Save and exit.

Step 3 – Configure Mattermost Systemd Service

Go to the systemd system directory and create a new mattermost service file.

Paste configuration below:

[Unit]

Description=Mattermost is an open source, self-hosted Slack-alternative

After=syslog.target network.target

[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

Save and exit.

Reload the systemd daemon and start the Mattermost service that we created above.

Make sure there is no error. Check that the Mattermost service is running.

Step 4 – Install and Configure Nginx

 

Install Nginx from Ubuntu repository with this apt command.

Now go to the Nginx config directory and create the SSL subdirectory.

Generate a new self-signed SSL certificate file with OpenSSL and change the permissions of the private key.

Create a new virtual host file for Mattermost in the ‘sites-available‘ directory.

Paste virtual host configuration below:

Change the domain name to your own domain, save and exit.

Activate the virtual host by creating a symlink to the mattermost file in the ‘sites-enabled‘ directory.

Test the Nginx configuration and make sure there is no error, and restart nginx.

 Share!

 
comments powered by Disqus