Hey, people kept asking me to write about how to setup your own chat, so here is a small manual for all of you and for my future reference. :) I hope it will be helpful, if you have any questions, please ask in the comments below.

So since you’re here I bet you already know why you need a chat server, what benefits will it provide and what problems you need to solve. Hopefully, this post will save you some headaches at least in the beginning.

Before you start

OK. First, you obviously need a server to run the service. I assume you know how to set up a virtual machine with the VPS provider of your choice, so I won’t go into much detail about it. I personally run virtual machines at Digital Ocean and recommend them as a great place for experiments. They’re really inexpensive and you can have a virtual machine up and running in minutes. Any distro will do, I use a long-term-support Ubuntu.

So if you have a virtual machine running, you’re ready for the next part.

DNS and SSL

This part is optional. If you want to give your server a name, make sure to register a domain and setup all DNS records you need. I recommend Namecheap for that. You may also want to create an SSL certificate to encrypt your chat traffic. You can buy an SSL certificate with your domain name on Namecheap or you can use a free alternative like Let’s Encrypt. I’ll give more details on how to use it in the next section.

Mattermost

Now we’re ready for the fun part. Enter Mattermost. If you’re familiar with Slack, then you might have heard about Mattermost. They’re sisters, one of them is more like an entrepreneur, the other one is more of a free artist. :)

Setting up

I will show you how to run a Mattermost server in Docker containers using docker-compose utility. It’s super easy.

Prepare

Before you start, please make sure that:

  1. you have docker installed - follow docker setup instructions,
  2. then make sure to install Docker Compose as we’ll need it to run Mattermost.

SSL certificate

This is optional, you can skip this section if you already have a certificate that you are going to use or if you don’t care about SSL, but I highly recommend taking time to run through it because it will make your chat secure. To setup a free Let’s Encrypt SSL certificate do this:

  • Setup a certbot utility. If your Linux disto does not provide it in a package, you can follow this little instruction to set it up manually.
  • Run this command and be sure to replace YOUR-DOMAIN-NAME with your server’s DNS name:
  $ certbot certonly --standalone -d YOUR-DOMAIN-NAME
  

Note: this command will try to run a temporary standalone webserver to talk to certification authority, so you need to have necessary ports open. If you run apache or nginx on your server, you may want to setup a virtual host first and then run certbot command without parameters - it will ask all information it needs.

Setting up Mattermost

Now, Mattermost’s site has various setup instructions but I think those are either too complicated or better suited for evaluation purposes. We need a production solution without too much hassle, right? So here is what needs to be done:

  • You need to clone a GitHub repository to some folder on your server. I put it under ~/repos folder:
$ git clone [email protected]:mattermost/mattermost-docker.git
  • If you have created an SSL certificate:
    • you need to open docker-compose.yml and set MATTERMOST_ENABLE_SSL to true.
      environment:
        - MATTERMOST_ENABLE_SSL=true
    
  • Put your SSL certificate as ./volumes/web/cert/cert.pem and the private key that has no password as ./volumes/web/cert/key-no-password.pem. If you generated a certificate with certbot, then copy those files from /etc/letsencrypt/archive/YOUR-DOMAIN-NAME folder and give them names which Mattermost expects. You can’t symlink files unfortunately because Mattermost server running in a docker container won’t be able to follow those links.

  • Build and run Mattermost:

$ docker-compose up -d
$ docker-compose start
  • Open https://your.domain with your web browser and follow setup instructions.

Result

Congratulations! Now you have your own chat server and you’re ready to invite friends to chat with!

Be sure to let me know about anything you found incomplete in this instruction.

Updating Mattermost

When time comes to update the Mattermost server application you need to do the following in the folder where your docker-compose.yml file is located:

  • Backup volumes folder to some place where it will be safe
  • Open up ./app/Dockerfile and replace the link to Mattermost’s archive package. Be sure to use a link to Open Source Team Edition version, not the Enterprise Edition. For example:
RUN curl https://releases.mattermost.com/3.5.1/mattermost-team-3.5.1-linux-amd64.tar.gz | tar -xvz
  • Completely stop and remove containers:
$ docker-compose down
  • Rebuild and run Mattermost:
$ docker-compose up -d
$ docker-compose start

Now you should have a fresh version of Mattermost server. You shouldn’t need to restore volumes folder, so if everything works as expected, you can delete the volumes folder backup. Let me know in the comments if these steps didn’t worked for you.