
Introduction
Mattermost is a free and open-source platform for developer collaboration and messaging. It's secure, flexible, and comes with a wide variety of tools to develop better workflows. Some notable features are two-factor authorization, video calls, file sharing capabilities, webhooks support, multi-threaded messaging, fully responsive user interfaces, and so on. Mattermost is an alternative to Slack. This article explains how to install Mattermost on Ubuntu 20.04.
Prerequisites
- Deploy a fully updated Vultr Ubuntu 20.04 Server.
- Create a non-root user with sudo access.
1. Install PostgreSQL Server
Update the system packages.
$ sudo apt updateInstall PostgreSQL database server.
$ sudo apt -y install postgresql-12 postgresql-contribEnable the database server to start automatically on system startup.
$ sudo systemctl enable postgresqlStart the database server.
$ sudo systemctl start postgresql2. Create Mattermost Database
Secure PostgreSQL by changing the default PostgreSQL password.
$ sudo passwd postgresSwitch to the postgres user.
$ su - postgresCreate a new database user named mattermostuser.
$ createuser mattermostuserLog in to the PostgreSQL instance.
$ psqlSet a secure password SecurePassword for the user.
ALTER USER mattermostuser WITH ENCRYPTED password 'SecurePassword';Create a database named mattermost and set the owner to mattermostuser.
CREATE DATABASE mattermost OWNER mattermostuser;Grant all the privileges on the database to the user.
GRANT ALL PRIVILEGES ON DATABASE mattermost to mattermostuser;Exit PostgreSQL instance.
\qReturn to your non-root sudo user account.
$ exit3. Install Mattermost
Create a system user and group called mattermost.
$ sudo useradd --system --user-group mattermostDownload the latest version of Mattermost. Please visit the official releases page to get the latest release.
$ wget https://releases.mattermost.com/6.4.0/mattermost-6.4.0-linux-amd64.tar.gzExtract the downloaded archive.
$ sudo tar xvf mattermost-6.4.0-linux-amd64.tar.gzMove the extracted file to the /opt directory.
$ sudo mv mattermost /optRemove the downloaded archive.
$ sudo rm mattermost-6.4.0-linux-amd64.tar.gzCreate the storage directory.
$ sudo mkdir -p /opt/mattermost/dataSet correct ownership and permissions.
$ sudo chown -R mattermost:mattermost /opt/mattermostGive write permissions to the Mattermost group.
$ sudo chmod -R g+w /opt/mattermost4. Configure Mattermost Server
Edit the configuration file to set up the database driver.
$ sudo nano /opt/mattermost/config/config.jsonLocate SqlSettings section and configure PostgreSQL database settings like bellow.
"DriverName": "postgres",
"DataSource": "postgres://mattermostuser:SecurePassword@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",Create Mattermost systemd service unit.
$ sudo nano /etc/systemd/system/mattermost.serviceAdd the below code into the file. Then, save and close the file:
[Unit]
Description=Mattermost Server
After=network.target
After=postgresql.service
Requires=postgresql.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=multi-user.targetReload systemd daemon for changes to take effect.
$ sudo systemctl daemon-reloadStart the Mattermost service.
$ sudo systemctl start mattermostEnable the service to run on system startup.
$ sudo systemctl enable mattermostCheck service status.
$ systemctl status mattermostAllow associated ports.
$ sudo ufw allow 8065/tcp
$ sudo ufw allow 80/tcp5. Create Reverse Proxy
Test the web interface, go to your browser and visit http://Server_IP:8065. For example:
http://192.0.2.11:8065Install Nginx server.
$ sudo apt install -y nginxUnlink Nginx default configuration file.
$ sudo unlink /etc/nginx/sites-enabled/defaultCreate new Nginx configuration file for named mattermost.conf.
$ sudo nano /etc/nginx/sites-available/mattermost.confAdd the following code to the file. Save and close the file.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8065;
}
}Enable the new configuration file.
$ sudo ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.confRestart the Nginx service.
$ sudo service nginx restartYou can now access the web interface without using a port. Go to your browser and visit http://Server_IP. For example:
http://192.0.2.11Conclusion
You have installed Mattermost on your Ubuntu 20.04 server. Access the installation page create your administrator account. You can now begin creating workflows.
More Information
To learn more about how to use Mattermost, go to the official documentation page.