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]
[/howToDirection]
The first user in your system should have administrator privileges.
[howToDirection]
Next, you will be prompted to create a new team.
[stepImage]
[/howToDirection]
[howToDirection]
Click the link Create a new team, then type the name of your team then press the Next button.
[stepImage]
[/howToDirection]
[howToDirection]
Now, you will be prompted to select a web for your new team.
[stepImage]
[/howToDirection]
[howToDirection]
Press the FinishÃÂ button. You will be directed to the Mattermost web interface. Log in as the administrator.
[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]
[/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]
[/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:
- Click here to know more about the Best website hosting.


