Install Mattermost with PostgreSQL on Ubuntu 16.04

Mattermost

Introduction

Mattermost is a workplace messaging system for web, PCs and phones. It’s an open source alternative to Slack.
A complete Mattermost installation consists of three components: the Mattermost server, a proxy server, and a database server. Each component can be installed on the same machine, or on three different machines on the local network.
This tutorial explains how to install Mattermost Team Edition on an Ubuntu 16.04 with Nginx as your proxy server and PostgreSQL as your database.

Install PostgreSQL

On the server that will host the database, execute the following command:

# apt install postgresql postgresql-contrib

During the installation process a new user, “postgres”, will be created. So, at the end, log in with the command:

$ sudo --login --user postgres

Start the PostgreSQL shell:

$ psql

Create a new database:

postgres=# CREATE DATABASE mattermost_db;
postgres=# CREATE USER mmuser WITH PASSWORD 'my_strong_password';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost_db to mmuser;
postgres=# \q

Log out of this account, and allow PostgresSQL to listen on all assigned IPs, editing the file /etc/postgresql/9.3/main/postgresql.conf
There, find line
#listen_addresses = 'localhost'
uncomment it and change ‘localhost’ to ‘*’; so, after editing:
listen_addresses = *
Reload the database with:

# systemctl reload postgresql

Now that the database is installed, it’s time to install the Mattermost Server.

Install Mattermost Server

Download the latest version of the Mattermost Server with wget. Right now, this is 3.6.2:

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

Extract the archive, and move to a different folder; for instance, in this example Mattermost will be stored on /opt:

# mv mattermost /opt

Create a storage directory, named “data”, in this folder:

# mkdir /opt/mattermost/data

The storage directory will contain all the files and images that users post to Mattermost, so it’s necessary that the drive that contains it is large enough.

Next, create a new user and a new group both named mattermost:

# useradd --system --user-group mattermost

Set the user and group mattermost as the owner of the Mattermost files with the command:

$ sudo chown -R mattermost:mattermost /opt/mattermost

Give the permissions to the Mattermost group:

sudo chmod -R g+w /opt/mattermost

Next, set up the database driver:

# $EDITOR /opt/mattermost/config/config.json

In that file, in the “SqlSettings” section, change “DriverName” and “DataSource” lines as follows:

"DriverName": "postgres"
"DataSource": "postgres://mmuser:[email protected]:5432/mattermost_db?sslmode=disable&connect_timeout=10",

Save and exit. Test the configuration, using “mattermost” user:

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

You will see that Mattermost is running on 127.0.0.1:8065. Stop it with CTRL+c.

Next, create a new mattermost service file for systemd:

# $EDITOR /etc/systemd/system/mattermost.service

And paste into this file the following text:

[Unit]
Description=Mattermost, an open source alternative to Slack
After=network.target
After=postgresql.service
Requires=postgresql.service

[Service]
Type=simple
ExecStart=/opt/mattermost/bin/platform
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost

[Install]
WantedBy=multi-user.target

Save and exit. Then:

# systemd daemon-reload

Now, start the service:

# systemctl start mattermost

Install Nginx

Install Nginx and configure Nginx as the reverse proxy for Mattermost. First:

# apt install nginx

Next:

# mkdir /etc/nginx/ssl
# cd /etc/nginx/ssl

Generate a new self-signed SSL certificate file:

# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/ssl/mattermost.crt -keyout /etc/nginx/ssl/mattermost.key
# chmod 400 mattermost.key

These will create a new certificate and change its permissions.
Next, create a new configuration file for mattermost in /etc/nginx/sites-available:

# $EDITOR /etc/nginx/sites-available/mattermost

and paste in it:

server {
   listen         80;
   server_name    mattermost.example.com;
   return         301 https://$server_name$request_uri;
}
 
server {
   listen 443 ssl;
   server_name mattermost.example.com;
 
   ssl on;
   ssl_certificate /etc/nginx/ssl/mattermost.crt;
   ssl_certificate_key /etc/nginx/ssl/mattermost.key;
   ssl_session_timeout 5m;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
   ssl_prefer_server_ciphers on;
   ssl_session_cache shared:SSL:10m;
 
   location / {
      gzip off;
      proxy_set_header X-Forwarded-Ssl on;
      client_max_body_size 50M;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      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_pass http://127.0.0.1:8065;
   }
}

Make sure to customize values for the Mattermost server IP address and FQDN for server_name.

Save, exit and activate the virtual host:

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

Test the configuration with:

# nginx -t

and then restart it, like this:

# systemctl restart nginx

Testing and conclusion

Last thing to do is a “graphical” configuration. With a web browser, go to URL mattermost.example.com.
There, create a new account. A dashboard will appear in which it’s possible to create new teams and/or access the admin/system console.
That’s all that is required for installing the messaging infrastructure for Mattermost.

  • [email protected]

    I’ve profited 104,000 thousand dollars in last twelve months by doing an online job from home a­n­d I manage to earn that much by work­ing in my own time for 3+ hrs every day. I used work opportunity I came across from this website i found online and I am so happy that I was able to earn so much extra income. It’s really beginner friendly a­­n­­d I’m so grateful that i discovered this. Here’s what I do… http://www­.­wzurl­.­me/fq_USw

  • [email protected]

    I’ve earned 104000 dollars previous year by working on-line and I did that by wo­rking in my own time for 3+ hrs a day. I was following an earning model I stumbled upon from this website i found online and I am so amazed that i was able to make so much extra income. It’s really beginner friendly a­n­d I’m just so grateful that i discovered this. Check out what I do… http://tny­.­im/8Ag

  • I have profited 104 thousand dollars in last 12 months by freelancing from my house and I manage to do it by wor­king part time for 3 or sometimes more hours daily. I was following work model I was introduced by this website i found online and I am so happy that i was able to make such great money. It’s very beginner friendly a­­n­­d I’m so blessed that i found this. Here’s what I did… http://gee­.­su/CY2sU

  • I was paid $104,000 previous year by working online from home and I did that by working part time for 3 or sometimes more h /day. I’m using an earning opportunity I stumbled upon from this website i found online and I am excited that i earned so much money on the side. It’s beginner-friendly and I am just so happy that i discovered it. Check out what I did… http://www.wzurl­.­me/tEXzrw

  • alice.masterson

    I got paid $104000 previous year by freelancing from home and I was able to do it by wo­rking part time f­­o­­r 3+ hrs a day. I was following an earning model I came across from this website i found online and I am happy that I was able to earn such great money. It’s very user-friendly a­­n­­d I’m so blessed that i learned about it. Check out what I did… http://www.wzurl­.­me/m7IQvg

  • bell_raymond

    I was paid 104000 dollars previous year by working from my home a­­n­­d I did it by work­ing part time for few hrs each day. I used a business model I was introduced by this website i found on-line and I am happy that i earned so much extra income. It’s so user friendly and I’m so thankful that i discovered it. This is what i do… http://urlof­.­site/LrOVY

  • [email protected]

    I was paid 104000 bucks last 12 months by doing an on-line work moreover I was able to do it by w­orking in my own time f­o­r several hours every day. I utilized work opportunity I came across on the internet and therefore I am delighted that I was capable of to make such great money. It is actually newbie-friendly and I’m so pleased that I discovered out about it. Take a look at what I do… I was without work for six months time when my former Co-worker lastly advised me to get into freelancing online… That was actually after I received $5000 in my initial 30 days when I really believed I could do this for a living! Currently I am happier than ever… I work at home and I am my own boss now that I always wanted… I see a lot of depressed people around me, working the same old boring job that’s sucking the everyday life from all of them day by day… Everytime I see any person like that I say START FREELANCING MAN! This is where I started >>>> www­.­cat­.­org­.­uk/snip/78276

  • [email protected]

    I was paid 104000 bucks past 12 month period by doing a web based job moreover I was able to do it by w­orking in my own time f­o­r several hours regularly. I used job opportunity I came across on the net and so I am excited that I was capable of to make such great money. It’s actually newbie-friendly and I am so delighted that I discovered out about it. Look into exactly what I do… www­.­cat­.­org­.­uk/snip/93439

  • lawrence_lee

    I was paid 104000 bucks last 12 months by doing an online task while I was able to do it by w­orking in my own time f­o­r quite a few hours on a daily basis. I utilized job opportunity I stumbled upon on the web and so I am thrilled that I was in a position to make such decent cash. It is seriously newbie-friendly and I’m so pleased that I found out regarding it. Have a look at what I do… http://polr­.­me/1g1h

  • I was paid 104000 dollars previous 12 month period by doing a web based task and consequently I was able to do it by w­orking in my own time f­o­r quite a few hours everyday. I applied job opportunity I found out over the internet and so I am thrilled that I was manage to earn such decent cash. It’s really newbie-friendly and therefore I’m so pleased that I found out about it. Look out for what I do… http://urll­.­in/jThFI

  • I was paid 104000 bucks last 12 months by doing an on-line work and I was able to do it by w­orking in my own time f­o­r several hours regularly. I applied job opportunity I found on the internet and also I am excited that I was succeed to make such decent cash. It’s genuinely newbie-friendly and therefore I’m so grateful that I discovered out about it. Find out more about what I do… http://ipt­.­pw/WGwiz6

  • mobley.barbara

    I was without work for six months when my early Fellow worker lastly strongly recommended me to begin freelancing from home… That was only just after I earned $5000 in my initial 30 days when I really believed I am able to do this for a living! Finally I am joyful than ever… I work-from-home as well as I am my own boss now like I always wanted… I see a large number of unhappy people around me, working the same old boring job that’s sucking the everyday life out of them day-after-day… Everytime I see any person like that I say START FREELANCING MAN! This is how I started >>>> http://flicom­.­ru/227487

  • I was paid 104000 bucks past 12 month period by doing an online work and I was able to do it by w­orking in my own time f­o­r quite a few hours on a daily basis. I applied job opportunity I came across over the internet and therefore I am thrilled that I was manage to earn such decent cash. It is actually newbie-friendly and therefore I am so pleased that I discovered out regarding it. Read through exactly what I do… http://olaurl­.­com/15cpx

  • I was without work for 6 months when my former Fellow worker lastly suggested me to get started with freelancing online… That was really after I gained $5000 in my initial month when I seriously believed I am able to do this for a living! Currently I am delightful than ever… I work-from-home and I am my own boss now that I always wanted… I see a large number of not satisfied people around me, working the same old boring job that is sucking the life from them day by day… Whenever I see anybody like that I say START FREELANCING MAN! This is how I started >>>> http://urll­.­in/mLdNm

  • Chief executive officer of Bing and Google!, is giving advice visitors to get started “Work at home” practice, that Marketers have been doing more than one year now. These days only, I made around $36k already with nothing but my desktop as well as some extra time, even though i have a fulltime nine to five job. Even everyone new to this, can earn $50/per h undoubtedly and the gains may go even higher over time… This is how i started >> http://adultadda­.­net/2Xm

  • M­a­n­y p­e­o­ple wish t­o ha­v­e a passive in­com­e at their, bu­t t­he­y do­n’t kno­w ho­w t­o exactly d­o th­at o­n th­e Int­ernet. Th­ere ar­e a many w­ays t­o ea­rn great am­ount of mo­ney, b­ut wh­enev­er p­eopl­e t­ry th­at the­y g­et tr­app­ed in a fraud, Therefore Now I am sh­aring wi­th yo­u a g­enuine an­d gu­arante­ed w­ay f­or fre­e to ea­rn hug­e am­ount of mon­ey a­t ho­me.I am earning atleast $10000 on a monthly basis since 12 months.Its an internet based work and easy to do, Even a little boy or girl can do this work and make money. If you want a happy and rich life then you should copy and paste this website in browser and then follow instructions to get started right now and earn Thousands Online……….. http://ipt­.­pw/mtV8cr