
Mattermost is an open-source messaging and collaboration platform that enables teams to communicate through real-time messaging, voice calls, and screen sharing. It is an alternative to platforms such as Slack, with support for file sharing, notifications, webhooks, and bot integrations.
This article explains how to deploy Mattermost on an Ubuntu server and configure it with a domain name. It covers integration with a Vultr Managed Database for PostgreSQL for high availability, Nginx as a reverse proxy with TLS certificates, Postfix for email notifications, and Vultr Object Storage for file storage.
Before you begin:
mattermost-data.mattermost.example.com.Mattermost stores user accounts, application data, and runtime configurations in a PostgreSQL database. Using a Vultr Managed Database offloads storage and backups from your server and provides automatic failover.
Install the PostgreSQL client package on your server.
Connect to your Vultr Managed Database for PostgreSQL cluster using the psql utility. Replace DB_HOST with your cluster hostname and DB_PORT with the connection port found in the Vultr Console.
Enter your Vultr Managed Database password when prompted.
Create a new database for Mattermost. For example, mattermostdb.
Create a new PostgreSQL user role for the database. For example, mmadmin.
Grant the user full privileges on the Mattermost database.
Grant the user access to all objects in the public schema.
Transfer ownership of the mattermostdb database to the new user.
Exit the PostgreSQL console.
Connect to the cluster using the Mattermost database and user. Replace DB_HOST and DB_PORT with your cluster connection details.
Enter the mmadmin password when prompted.
List all databases to verify that mattermostdb appears with mmadmin as the owner.
Verify that mattermostdb appears in the list with mmadmin as the owner.
Exit the PostgreSQL console.
Mattermost distributes packages through its own apt repository. Adding the repository GPG key and running the setup script imports all repository metadata and ensures package authenticity.
Add the Mattermost GPG public key to the server keyring.
Download and run the Mattermost repository setup script.
The script imports the Mattermost repository information on your server.
Update the server package index.
Install Mattermost.
Check the Mattermost service status to verify that the package is installed.
The service is installed but not running. The next section configures the database connection and domain before the service starts.
Mattermost creates the /opt/mattermost directory on your server containing the full application and configuration files. The config/config.json file within that directory controls the database connection, site URL, and all other runtime settings.
Navigate to the Mattermost configuration directory.
Copy the default configuration file and rename it to config.json.
Transfer ownership of config.json to the Mattermost system user.
Set the file permissions to 600 to prevent other system users and processes from reading the file.
List the directory contents to verify the permission changes.
The rw------- permissions on config.json confirm that only the Mattermost user can read or write the file.
Open config.json in a text editor.
Find the ServiceSettings section and set SiteURL to your domain. Replace mattermost.example.com with your actual domain.
Find the SqlSettings section and replace the DataSource value with your Vultr Managed Database connection string. Replace mmadmin, your-password, DB_HOST, DB_PORT, and mattermostdb with your actual values. Also change sslmode from disable to require.
Save and close the file.
Start the Mattermost service to validate and apply the configuration.
Wait at least 5 minutes for Mattermost to apply all configurations and write the initial data to the PostgreSQL database. If the service fails to start, check the logs to identify the error.
Check the Mattermost service status to verify that it is running.
Verify that the output shows Active: active (running).
Mattermost listens on port 8065 by default and is not directly exposed to the internet. Nginx acts as a reverse proxy, accepting public connections on ports 80 and 443 and forwarding them to the Mattermost backend.
Update the server package index.
Install Nginx.
Remove the default Nginx configuration to avoid conflicts on port 80.
Create a new Nginx configuration file for Mattermost. Replace mattermost.example.com with your domain.
Add the following configuration, replacing mattermost.example.com with your actual domain.
Save and close the file.
The configuration redirects all HTTP connections to HTTPS and forwards both standard requests and WebSocket connections to Mattermost on port 8065.
Link the configuration file to the sites-enabled directory. Replace mattermost.example.com with your actual domain name.
Do not restart Nginx yet. TLS certificates must exist at the paths referenced in the configuration before Nginx can start without errors.
Ubuntu's Uncomplicated Firewall (UFW) restricts incoming connections by default. Open ports 80 and 443 to allow Let's Encrypt domain validation and HTTPS access, then generate TLS certificates for your domain.
Allow HTTP traffic on port 80 for Let's Encrypt domain validation.
Allow HTTPS traffic on port 443 for secure client access.
Reload UFW to apply the changes.
Check the firewall rules to verify that ports 80 and 443 are open.
Install the Certbot plugin for Nginx.
Generate TLS certificates for your domain using the certonly option to avoid Certbot modifying the Nginx configuration. Replace mattermost.example.com with your actual domain.
Enter your email address when prompted. Verify that the output confirms that the certificate files are saved at /etc/letsencrypt/live/mattermost.example.com/.
Test the Nginx configuration for syntax errors.
Expected output:
Restart Nginx to apply the Mattermost configuration.
Mattermost displays a setup wizard on first access to create the administrator account and configure the workspace.
Open a web browser and navigate to your Mattermost domain.
Verify that the Mattermost setup interface loads in your browser.
Click View in Browser to access the account setup options.
Enter your email address in the Email address field within the Create your account form.
Enter your administrator username in the Choose a Username field, then enter a strong password.
Click Create Account to create the administrator account.
Enter your workspace name in the Organization name field.
Select the external tools to activate in your Mattermost workspace and click Continue to save the selection. For example, select GitHub and Zoom.
Click Copy Link to copy and share your Mattermost invite link with your target users.
Click Finish setup to apply the configuration and open the Mattermost workspace.
Click Browse or Create Channels next to your Mattermost team name to set up a new channel.
Select Create new channel from the list of options.
Enter a channel name and set your visibility options. For example, enter mynewteam and select Public Channel to allow all workspace users to access the channel.
Enter a channel description and click Create channel.
Verify that the channel appears in the Channels list.
Enter a sample message in the channel to verify that the server is working correctly. For example, enter Hello World! This is a new Mattermost server and press Enter to send the message.
Verify that the message appears in the channel.
Open the main Mattermost menu next to Channels on the top navigation bar and select System Console to open the administrator console. Alternatively, navigate to /admin_console on your domain.
Verify that the Mattermost administrator console loads and displays the edition and license version installed on your server.
Find the USER MANAGEMENT section in the main navigation menu and click Users to view the list of workspace users.
Verify the user list and click the Actions menu to modify user roles.
Click Save to apply your changes.
Find the AUTHENTICATION section in the main navigation menu and click Signup to configure how users register.
Enter a comma-separated list of domain names in the Restrict new system and team members…. field to limit registration to specific email domains. For example, enter example.com,example.net.
Set Enable Open Server to true to allow new users with matching email domains to create accounts. Keep it set to false to disable self-registration and accept only invited users.
Click Save to apply the workspace configuration.
Mattermost sends notifications through an SMTP server. A Preview Mode: Email notifications have not been configured. alert displays in the interface when email is not configured. These steps install and configure Postfix as a send-only SMTP server for outgoing notifications.
SMTP port 25 is blocked on Vultr servers by default. Contact Vultr Support to enable it on your account.
Update the server package index.
Set the server hostname to your Mattermost domain. Replace mattermost.example.com with your actual domain.
Install the Postfix mailutils package.
When prompted, select Internet Site and enter your domain as the system mail name.
Back up the original Postfix configuration file.
Open the Postfix configuration file.
Find the inet_interfaces directive and change its value from all to loopback-only.
Find the mydestination directive and replace its value with the following.
Save and close the file.
Restart Postfix to apply the configuration changes.
Send a test email to verify that Postfix is working. Replace johndoe@example.com with your email address.
Check the server logs to verify that the email was sent.
Output:
Check your inbox to verify that an email from server-username@your-mattermostdomain arrived. Emails sent to domains such as gmail.com may bounce due to missing MX and SPF DNS records on your domain.
Open the Mattermost administrator console.
Find the ENVIRONMENT section in the main navigation menu and click SMTP to modify the email configuration.
Keep localhost as the SMTP Server value.
Replace the default value 10025 with 25 in the SMTP Server Port field.
Set Skip Server Certificate Verification to true to disable verification of the Postfix certificate.
Click Save to apply the SMTP configuration.
Click Test Connection to validate the SMTP connection. Verify that a No errors were reported while sending an email. Please check your inbox to make sure. message appears.
By default, Mattermost stores file and image attachments in /opt/mattermost/data. Vultr Object Storage provides an S3-compatible endpoint that Mattermost can use instead, keeping attachments off the server disk.
Open the Mattermost administrator console.
Find the ENVIRONMENT section in the main navigation menu and click File Storage.
Click the File Storage System dropdown and select Amazon S3.
Enter your Vultr Object Storage bucket name in the Amazon S3 Bucket field.
Leave the Amazon S3 Path Prefix and Amazon S3 Region fields empty.
Enter your Vultr Object Storage access key in the Amazon S3 Access Key ID field.
Enter your Vultr Object Storage hostname in the Amazon S3 Endpoint field.
Enter your Vultr Object Storage secret key in the Amazon S3 Secret Access Key field.
Keep Enable Secure Amazon S3 Connections set to true.
Click Save to apply the file storage configuration.
Click Test Connection to validate the credentials. Verify that a Connection was successful message appears.
Mattermost provides client applications for Android, iOS, and desktop. Each client connects to your self-hosted server using the server URL and your workspace credentials.
Download and install the Mattermost application for your device. For example, Mattermost for Android.
Open the Mattermost application on your device.
Click Get Started.
Enter your Mattermost domain URL in the Server URL field.
Enter a display name in the Server display name field to identify your Mattermost workspace on the device.
Verify that a Server URL is valid. Server version: prompt appears below the URL field and click Connect.
Enter your workspace email and password to log in.
To create a new user account, click Don't have an account to access the signup form. When the account is created, open your invite link in a browser and log in to join a Mattermost channel.
Verify that the client application can access all enabled channels on the server.
You have deployed Mattermost on an Ubuntu server with a managed PostgreSQL database, Nginx reverse proxy with TLS, Postfix for email notifications, and Vultr Object Storage for file attachments. For more information, visit the Mattermost documentation.
0 Comments
Be the first to comment and share your perspective with the community.