
Managing Digitalux on AWS EC2 with Hostinger: Powerful Lessons Learned
Deploying and managing a secure and scalable infrastructure is a critical part of running any digital business. At Digitalux, we
Meta Description:
This Step-by-step guide to developing Mattermost, helps DevOps engineers, admins, and developers to set up a secure, scalable platform. For deploying Mattermost on AWS with EC2, RDS, S3, NGINX, and SMTP.
Effective team communication is very important for a smooth workflow. Mattermost, an open-source, self-hosted messaging platform, provides secure and flexible collaboration for businesses and developers. Deploying Mattermost on Amazon Web Services (AWS) ensures high availability, scalability, and security. This guide offers a detailed, step-by-step lead for deploying Mattermost__ a secure, self-hosted alternative to Slack, on AWS EC2.
You’ll learn how to configure AWS RDS for efficient database management, set up AWS S3 for reliable media storage, and integrate SMTP (smtp.titan.email) to enable email notifications. Additionally, this guide addresses common setup challenges and provides troubleshooting solutions, ensuring technical teams can replicate the deployment smoothly and optimize Mattermost for scalability, security, and high performance.
This blog will provide a Comprehensive technical guide on deploying Mattermost on AWS with:
By the end of this blog, you’ll have a fully functional Mattermost instance running on AWS.
Step-by-step guide to developing Mattermost on AWS, we need the following prerequisites:
For deploying Mattermost On AWS, we follow the following steps:
Installing and running the Mattermost server on an AWS EC2 instance (a virtual machine in the cloud) is the first step.
Ensure the following inbound rules are set:
| Type | Protocol | Port Range | Source | Description |
|---|---|---|---|---|
| SSH | TCP | 22 | Your IP (x.x.x.x/32) | Allow SSH access |
| HTTP | TCP | 80 | Anywhere (0.0.0.0/0) | Allow web traffic |
| HTTPS | TCP | 443 | Anywhere (0.0.0.0/0) | Allow secure web traffic |
| Custom TCP | TCP | 8065 | Anywhere (0.0.0.0/0) | Mattermost server port |
Note: Restrict SSH access to your IP for security.
your-db-instance-id.mmuser.5432.mattermost.| Type | Protocol | Port Range | Source | Description |
|---|---|---|---|---|
| PostgreSQL | TCP | 5432 | EC2 Security Group ID | Allow EC2 to access RDS |
Note: Replace EC2 Security Group ID with the actual ID of your EC2 instance’s security group.
your-bucket-name (Ensure the name is unique globally)To allow Mattermost to interact with S3 securely, create an IAM role with the necessary permissions.
your-bucket-name with your actual bucket name:{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::your-bucket-name"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::your-bucket-name/*"
]
}
]
}
MattermostS3AccessPolicy.Policy to allow Mattermost access to S3 bucket for media storage.MattermostS3AccessPolicy and select it.MattermostS3AccessRole.IAM role for Mattermost to access S3 bucket for media storage.MattermostS3AccessRole.your-mattermost-url.| Setting | Value | Description |
|---|---|---|
| Amazon S3 Access Key ID: | (Leave blank if using IAM Role) | Not required if IAM role is attached to EC2 instance. |
| Amazon S3 Secret Access Key: | (Leave blank if using IAM Role) | Not required if IAM role is attached to EC2 instance. |
| Amazon S3 Bucket: | your-bucket-name | Your S3 bucket name. |
| Amazon S3 Region: | (Select your bucket’s region) | e.g., eu-north-1 |
| Use SSL: | True | Enable SSL for secure connections. |
| Bucket Path: | (Optional) | Path within the bucket to store files. |
| Endpoint: | (Leave blank unless using a custom endpoint) | For standard S3 usage, leave blank. |
| Force Path Style: | False | Typically, False unless required by your setup. |
Use SSH to connect:
ssh -i /path/to/your/private-key.pem ubuntu@ec2-16-171-171-121.eu-north-1.compute.amazonaws.com
sudo apt update && sudo apt upgrade -y
sudo apt install -y wget curl gnupg2 software-properties-common
sudo apt install -y postgresql-client
wget <https://releases.mattermost.com/7.3.1/mattermost-7.3.1-linux-amd64.tar.gz>
2. Extract the Archive:
tar -xvzf mattermost-7.3.1-linux-amd64.tar.gz
sudo mv mattermost /opt
sudo mkdir /opt/mattermost/data
3. Create a Mattermost User:
sudo useradd --system --user-group mattermost
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost
sudo nano /opt/mattermost/config/config.json
2. Update Database Settings:
Locate the SqlSettings section and update as follows:
"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser:s3cr3tpassword@mattermost-db.cfq2jxyzabcd.us-east-1.rds.amazonaws.com:5432/mattermost?sslmode=require&connect_timeout=10",
...
},
Replace:
Locate the SqlSettings section and update as follows:
"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser:s3cr3tpassword@mattermost-db.cfq2jxyzabcd.us-east-1.rds.amazonaws.com:5432/mattermost?sslmode=require&connect_timeout=10",
...
},
Replace:
mmuser with your RDS master username.s3cr3tpassword with your RDS master password.mattermost-db.cfq2jxyzabcd.us-east-1.rds.amazonaws.com with your RDS endpoint.sslmode=require for secure connections.2. Save and Exit:
Ctrl + O, then Enter.Ctrl + X to exit.sudo nano /etc/systemd/system/mattermost.service
2. Add the Following Content:
[Unit]
Description=Mattermost
After=network.target
[Service]
Type=notify
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
Restart=always
RestartSec=10
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target
3. Save and Exit:
Ctrl + O, then Enter.Ctrl + X to exit.4. Start and Enable Mattermost Service:
sudo systemctl daemon-reload
sudo systemctl start mattermost
sudo systemctl enable mattermost
5. Verify Service Status:
sudo systemctl status mattermost
Ensure the service is active and running.
5.1. Install NGINX
sudo apt install -y nginx
5.2. Configure NGINX for Mattermost:
sudo nano /etc/nginx/sites-available/mattermost
Add the Following Configuration:
server {
listen 80;
server_name chat.digitalux.pk;
# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name chat.digitalux.pk;
ssl_certificate /etc/letsencrypt/live/chat.digitalux.pk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/chat.digitalux.pk/privkey.pem;
# Increase upload size limit
client_max_body_size 100M;
location / {
proxy_pass <http://localhost:8065>;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Note:
server_name to your domain.3. Enable the Configuration:
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
4. Test NGINX Configuration:
sudo nginx -t
Expected Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
5. Reload NGINX:
sudo systemctl reload nginx
Use Certbot for Let’s Encrypt SSL certificates.
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d chat.digitalux.pk
Certbot sets up a cron job by default. Verify with:
sudo systemctl status certbot.timer
After initial SMTP configuration attempts with Hostinger failed, switching to smtp.titan.email resolved the issue. Below is the step-by-step guide for configuring SMTP using Titan’s SMTP server.
smtp.titan.email465587465587your-usernameyour-password (Ensure this is correct and complete)your-mattermost-url.2. Fill in the SMTP Configuration:
| Setting | Value | Description |
|---|---|---|
| SMTP Server: | smtp.titan.email | Hostname of Titan’s SMTP server. |
| SMTP Server Port: | 465 (for SSL) or 587 (for STARTTLS) | Port number based on the encryption method you choose. |
| Enable SMTP Authentication: | True | Enable SMTP Authentication to allow Mattermost to authenticate with the SMTP server. |
| SMTP Server Username: | your-username | Your full email address as the SMTP username. |
| SMTP Server Password: | `s9XL | EfOGb1mC_KHideCopy` |
| Connection Security: | SSL or STARTTLS | Choose SSL if you’re using port 465 or STARTTLS if you’re using port 587. |
| Skip Server Certificate Verification: | False | Recommended: Keep this False to ensure secure email transmission. Set to True only if necessary. |
| Enable Security Alerts: | True | Enable to receive security-related email alerts from Mattermost. |
3. Detailed Configuration Steps:
smtp.titan.email.465 with SSL.587 with STARTTLS.your-username.your-password. (Ensure this is the complete password)465.587.smtp.titan.email.465 with SSL.587 with STARTTLS.your-username.your-password. (Ensure this is the complete password)465.587.4. Save the Configuration:
Click “Save” or “Apply” to update the settings.
Connection unsuccessful: authentication failed: 535 5.7.8 Error: authentication failed: (reason unavailable)
smtp.titan.email) resolved the authentication issues.Thunderbird failed to find the settings for your email account.
This section documents the challenges faced during the setup process and their solutions to aid future troubleshooting.
There was a problem uploading your files.
client_max_body_size was set to 1MB, limiting the size of client requests.sudo nano /etc/nginx/sites-available/mattermost
2. Add/ Modify client_max_body_size:
client_max_body_size 100M;
3. Save and Exit:
Ctrl + O, then Enter.Ctrl + X to exit.4. Test NGINX Configuration:
sudo nginx -t
5. Reload NGINX:
sudo systemctl reload nginx
6. Verify in Mattermost:
ssh: connect to host ec2-16-171-171-121.eu-north-1.compute.amazonaws.com port 22: Operation timed out
22) from your IP.iptables or other firewalls on the instance allow SSH traffic.sudo systemctl restart sshd
7. Attempt SSH Connection Again:
ssh -i /path/to/your/private-key.pem ubuntu@ec2-16-171-171-121.eu-north-1.compute.amazonaws.com
8. Contact AWS Support:
Connection unsuccessful: authentication failed: 535 5.7.8 Error: authentication failed: (reason unavailable)
Thunderbird failed to find the settings for your email account.
465, STARTTLS with 587).EC2 Instance Connect is unable to connect to your instance. Ensure your instance network settings are configured correctly for EC2 Instance Connect.
sudo apt update
sudo apt install ec2-instance-connect -y
2. Configure SSHD for EC2 Instance Connect:
sudo nano /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysCommand /opt/aws/bin/eic_run_authorized_keys %u %f
AuthorizedKeysCommandUser ec2-instance-connect
3. Restart SSH Service:
sudo systemctl restart sshd
4. Review Security Groups and Network ACLs:
5. Use EC2 Instance Connect via AWS Console:
MattermostS3AccessRole has the correct policies attached.aws s3 ls s3://mattermost-media-digitalux-pk --region your-region
5. Review Mattermost Logs for S3 Errors:
sudo journalctl -u mattermost -f
6. Ensure Correct Configuration in Mattermost:
Best practices for managing a self-hosted platform include:
10. Ensure Your Platform Meets Business-Specific Needs
Deploying Mattermost on AWS EC2 with AWS RDS, AWS S3, and configuring SMTP for email notifications involves several critical steps, each essential for the seamless operation of your communication platform. By following this guide, you can set up a robust, secure, and efficient Mattermost server tailored to your organization’s needs. Additionally, documenting the challenges encountered and their resolutions serves as a valuable resource for future troubleshooting and for other team members embarking on a similar setup.
Disclaimer: Always handle sensitive information, such as passwords and SSH keys, securely. Avoid sharing credentials publicly and consider using environment variables or secrets management tools for enhanced security.

Deploying and managing a secure and scalable infrastructure is a critical part of running any digital business. At Digitalux, we

Introduction: Deploy Node.js App on AWS EC2 (Elastic Compute Cloud) is a service provided by Amazon Web Services that allows

Introduction: At Digitalux, we constantly strive to enhance team productivity by integrating powerful tools into our workflows. In modern work
2024@Digitalux All right reserved