Mattermost is an open-source, self-hosted chat and collaboration platform that is designed for modern teams. Mattermost is an alternative to Slack.
In this tutorial, we will show you the complete steps to install Mattermost
on Ubuntu 22.04 with PostgreSQL database server.
Step 1: Update Operating System
Update your Ubuntu 22.04 operating system to the latest version with the following command:
# apt update && sudo apt upgrade -y
Step 2: Install Nginx webserver
You can install Nginx via apt
package manager by executing the following command.
# apt install nginx
You can start the Nginx service and configure it to run on startup by entering the following commands:
# systemctl start nginx
# systemctl enable nginx
Verify the status of the Nginx
service using systemctl status
command:
# systemctl status nginx
Output:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running)
Docs: man:nginx(8)
Process: 5421 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 5422 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 5423 (nginx)
Tasks: 2 (limit: 2196)
Memory: 6.7M
CPU: 327ms
CGroup: /system.slice/nginx.service
├─5423 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
└─5424 "nginx: worker process"
Step 3: Install PostgreSQL Database Server
Run the apt command to install:
# apt install postgresql postgresql-contrib
Once successfully installed, enable PostgreSQL (to start automatically upon system boot), start, and verify the status using the commands below:
# systemctl enable postgresql
# systemctl start postgresql
# systemctl status postgresql
Next, run the command below to log in to the PostgreSQL you just installed above:
su postgres
psql
Then, we create the Mattermost
database:
postgres=# CREATE DATABASE mattermostdb;
postgres=# CREATE USER mattermost WITH PASSWORD 'Mattermost-Strong-Password';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermostdb to mattermost;
postgres=# \q
Return to your root
user account.
# exit
Step 4: Create mattermost System user and group
We need to set up a system user and group called mattermost that will run service.
# useradd --system --user-group mattermost
You can confirm it is a system user since its ID is less than 1000.
# id mattermost
uid=998(mattermost) gid=998(mattermost) groups=998(mattermost)
Step 5: Installing Mattermost on Ubuntu 22.04
By default, Mattermost
is not available on Ubuntu 22.04 base repository. Please visit the official releases page to get the latest release.
Run the following command to download the latest version of Mattermost to your Ubuntu system:
# wget https://releases.mattermost.com/7.5.2/mattermost-7.5.2-linux-amd64.tar.gz
Extract the downloaded file to /opt
directory using tar
command:
# tar xpvf mattermost-7.5.2-linux-amd64.tar.gz -C /opt
Create the data storage directory for the Mattermost server.
# mkdir /opt/mattermost/data
Set the correct permissions on files and directories:
# chown mattermost:mattermost /opt/mattermost/ -R
Step 6: Configure Mattermost Server
Edit the configuration file to set up the database driver.
# nano /opt/mattermost/config/config.json
Locate SqlSettings section and configure PostgreSQL database settings like bellow:
"DriverName": "postgres",
"DataSource": "postgres://mattermost:Mattermost-Strong-Password@localhost:5432/mattermostdb?sslmode=disable&connect_timeout=10",
Step 7: Create a Systemd service file
Create systemd unit for Mattermost
to start / stop and restart service.
# nano /etc/systemd/system/mattermost.service
Paste following lines:
[Unit]
Description=Mattermost
After=network.target
After=postgresql.service
BindsTo=postgresql.service
[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
KillMode=mixed
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target
Reload system daemon and start Mattermost Service:
# systemctl daemon-reload
# systemctl start mattermost
# systemctl enable mattermost
To confirm everything is working normally, check the status of service:
# systemctl status mattermost
Output:
● mattermost.service - Mattermost
Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: enabled)
Active: active (running)
Main PID: 4366 (mattermost)
Tasks: 49 (limit: 2196)
Memory: 539.5M
CPU: 13.944s
CGroup: /system.slice/mattermost.service
├─4366 /opt/mattermost/bin/mattermost
├─4395 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
├─4406 plugins/com.mattermost.calls/server/dist/plugin-linux-amd64
├─4419 plugins/playbooks/server/dist/plugin-linux-amd64
├─4427 plugins/focalboard/server/dist/plugin-linux-amd64
└─4443 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
Step 8: Configure Nginx for Mattermost
Then, create an virtual host configuration file:
# nano /etc/nginx/sites-available/mattermost.conf
Add the following code to the file:
server {
listen 80;
server_name mattermost.your-domain.com;
root /opt/mattermost;
error_log /var/log/nginx/mattermost.error;
access_log /var/log/nginx/mattermost.access;
location / {
proxy_pass http://localhost:8065;
}
}
Remember to replace your-domain.com
with the domain name of your server.
Save and exit the configuration file.
Enable the new configuration file.
# ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf
Check Nginx syntax:
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
To implement the changes, restart Nginx webserver:
# systemctl restart nginx
Step 9: Mattermost Setup and Configurations
Now open your web browser and go to http://mattermost.your-domain.com
and you will see the following screen:
Next, you will be taken to the Team creation page:
Click the Create a team
button to create your first team:
Then you will be asked to set a public URL for the team:
Click the Finish button to open the Mattermost Dashboard:
Comments and Conclusion
That’s it. You have successfully installed Mattermost
on Ubuntu 22.04 with Nginx. For additional information, you can check the official Mattermost documentation.
If you have any questions please leave a comment below.