Rocket.Chat Installation and Configuration

Rocket.Chat is a fully customizable, open-source communication platform providing team messaging, video conferencing, and team collaboration tools. Built on Node.js and MongoDB, Rocket.Chat offers features comparable to Slack while allowing complete data ownership and self-hosting. This comprehensive guide covers installation, MongoDB setup, Nginx configuration, SSL encryption, user management, and administration configuration.

Table of Contents

Prerequisites

Ensure you have:

  • Ubuntu 20.04 LTS or later
  • Root or sudo access
  • A valid domain name
  • Minimum 4GB RAM (8GB+ recommended)
  • 20GB available disk space
  • Basic Linux administration knowledge

Update system packages:

sudo apt update && sudo apt upgrade -y

System Requirements

Verify system specifications:

Check OS version:

cat /etc/os-release
uname -m

Verify available resources:

free -h
df -h

Install required tools:

sudo apt install -y curl wget git build-essential python3

Node.js Installation

Install Node.js 16 LTS or later:

Add NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Install Node.js:

sudo apt install -y nodejs

Verify installation:

node --version
npm --version

Install global Node.js tools:

sudo npm install -g forever

MongoDB Setup

Install MongoDB:

sudo apt install -y mongodb

Start and enable MongoDB:

sudo systemctl start mongodb
sudo systemctl enable mongodb

Verify MongoDB is running:

sudo systemctl status mongodb

Create MongoDB replica set (required for Rocket.Chat):

Access MongoDB shell:

mongo

Initialize replica set:

rs.initiate()
exit

Create Rocket.Chat database and user:

mongo << EOF
use rocketchat
db.createUser({
  user: 'rocketchat',
  pwd: 'SecurePassword123!',
  roles: [
    { role: 'dbOwner', db: 'rocketchat' },
    { role: 'readWrite', db: 'rocketchat' }
  ]
})
exit
EOF

Enable authentication in MongoDB:

sudo nano /etc/mongodb.conf

Add:

security:
  authorization: "enabled"

Restart MongoDB:

sudo systemctl restart mongodb

Test connection:

mongo -u rocketchat -p 'SecurePassword123!' --authenticationDatabase rocketchat
show collections
exit

Rocket.Chat Installation

Create Rocket.Chat installation directory:

sudo mkdir -p /opt/rocketchat
sudo chown -R $(whoami):$(whoami) /opt/rocketchat
cd /opt/rocketchat

Download latest Rocket.Chat release:

wget https://releases.rocket.chat/latest/download -O rocketchat.tgz
tar -xzf rocketchat.tgz

Install Node.js dependencies:

cd bundle/programs/server
npm install

Change ownership to dedicated user:

sudo useradd -r -s /bin/false -m -d /opt/rocketchat rocketchat
sudo chown -R rocketchat:rocketchat /opt/rocketchat

Create systemd service file:

sudo nano /etc/systemd/system/rocketchat.service

Add:

[Unit]
Description=Rocket.Chat
After=network.target mongodb.service

[Service]
Type=simple
User=rocketchat
Group=rocketchat
WorkingDirectory=/opt/rocketchat
Environment="ROOT_URL=https://chat.example.com"
Environment="PORT=3000"
Environment="MONGO_URL=mongodb://rocketchat:SecurePassword123!@localhost:27017/rocketchat?authSource=rocketchat"
Environment="MONGO_OPLOG_URL=mongodb://rocketchat:SecurePassword123!@localhost:27017/local?authSource=admin"
ExecStart=/usr/bin/node main.js
Restart=always
RestartSec=30
StartLimitInterval=200
StartLimitBurst=5

[Install]
WantedBy=multi-user.target

Enable and start Rocket.Chat:

sudo systemctl daemon-reload
sudo systemctl enable rocketchat
sudo systemctl start rocketchat

Verify service:

sudo systemctl status rocketchat
sudo journalctl -u rocketchat -f

Wait for Rocket.Chat to fully start (may take 1-2 minutes).

Nginx Configuration

Install Nginx:

sudo apt install -y nginx

Create Nginx configuration:

sudo nano /etc/nginx/sites-available/rocketchat

Add:

server {
    listen 80;
    listen [::]:80;
    server_name chat.example.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name chat.example.com;

    ssl_certificate /etc/letsencrypt/live/chat.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/chat.example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;

    client_max_body_size 100M;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_request_buffering off;
        proxy_set_header Host $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 Connection "upgrade";
        proxy_set_header Upgrade $http_upgrade;
        proxy_read_timeout 86400s;
        proxy_send_timeout 86400s;
    }
}

Enable site:

sudo ln -s /etc/nginx/sites-available/rocketchat /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl start nginx
sudo systemctl enable nginx

SSL Certificate Setup

Install Certbot:

sudo apt install -y certbot python3-certbot-nginx

Obtain SSL certificate:

sudo certbot certonly --standalone -d chat.example.com

Verify certificate:

sudo openssl x509 -in /etc/letsencrypt/live/chat.example.com/fullchain.pem -noout -dates

Set up auto-renewal:

sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer

Admin Configuration

Access Rocket.Chat web interface:

Navigate to https://chat.example.com and complete the setup wizard:

  1. Create admin account
  2. Configure workspace name and type
  3. Set organization name
  4. Configure email

Configure administrator settings:

  1. Click avatar → Administration
  2. Go to Workspace → Settings
  3. Configure:

Enable email notifications:

  1. Administration → Mailers
  2. Configure SMTP:
    • SMTP Host
    • SMTP Port
    • User/Password
    • From Email

User Management

Create users:

  1. Administration → Users
  2. Click "New User"
  3. Enter username, email, password
  4. Assign roles (User, Moderator, Owner)

Configure authentication:

  1. Administration → Workspace → Settings → Accounts
  2. Enable email registration (optional)
  3. Set password requirements
  4. Enable two-factor authentication

Create teams and channels:

  1. Click "+" icon in sidebar
  2. Create new channel or team
  3. Set privacy (Public/Private)
  4. Add members

Integration Setup

Enable webhooks:

  1. Administration → Workspace → Integrations
  2. Create new integration
  3. Set event triggers and payload URL

Configure OAuth:

  1. Administration → Workspace → OAuth Applications
  2. Create new application
  3. Set redirect URL and permissions

Setup GitHub integration:

  1. Administration → Workspace → Integrations → GitHub
  2. Configure bot credentials
  3. Enable GitHub notifications

Enable REST API:

  1. Create API token in user profile
  2. Use for programmatic access

Backup and Updates

Create backup script:

sudo nano /usr/local/bin/rocketchat-backup.sh

Add:

#!/bin/bash

BACKUP_DIR="/backups/rocketchat"
DATE=$(date +%Y%m%d_%H%M%S)

mkdir -p $BACKUP_DIR

# Stop Rocket.Chat
sudo systemctl stop rocketchat

# Backup MongoDB
mongodump -u rocketchat -p 'SecurePassword123!' --authenticationDatabase rocketchat --db rocketchat --gzip --archive="$BACKUP_DIR/rocketchat-db-$DATE.archive"

# Start Rocket.Chat
sudo systemctl start rocketchat

# Keep only 30 days of backups
find $BACKUP_DIR -type f -mtime +30 -delete

echo "Backup completed: $DATE"

Make executable:

sudo chmod +x /usr/local/bin/rocketchat-backup.sh

Schedule daily backups:

sudo crontab -e

Add:

0 2 * * * /usr/local/bin/rocketchat-backup.sh >> /var/log/rocketchat-backup.log 2>&1

Update Rocket.Chat:

sudo systemctl stop rocketchat
cd /opt/rocketchat
wget https://releases.rocket.chat/latest/download -O rocketchat.tgz
tar -xzf rocketchat.tgz
cd bundle/programs/server
npm install
sudo chown -R rocketchat:rocketchat /opt/rocketchat
sudo systemctl start rocketchat

Conclusion

Rocket.Chat is now fully installed and configured as a self-hosted team communication platform. With MongoDB database, Nginx reverse proxy, SSL encryption, and proper admin configuration, you have a powerful alternative to commercial messaging services. Regular backups and updates maintain system reliability and security. Create teams, channels, and integrations to build a collaborative workspace tailored to your organization's needs.