Jul 6, 2024 3 min read

Rocket.Chat: The Ultimate Self-Hosting Setup

Rocket.Chat: The Ultimate Self-Hosting Setup
Table of Contents

Rocket.Chat is an open-source, self-hosted communication platform designed to provide secure, flexible, and highly customizable collaboration for teams. It’s an excellent choice for organizations that need complete control over their data and want a feature-rich alternative to proprietary messaging platforms. In this guide, we’ll cover everything from installing Rocket.Chat to configuring it with Nginx, managing logs, creating backups, and leveraging its advanced features.

Installing Rocket.Chat

πŸ“¦ Docker/Docker Compose Setup

Docker is the most efficient method for deploying Rocket.Chat, as it simplifies dependency management and provides portability.

  1. Create a docker-compose.yml file to define the Rocket.Chat and MongoDB containers:

version: '3'

services:

rocketchat:

image: rocketchat/rocket.chat:latest

restart: unless-stopped

environment:

MONGO_URL: mongodb://mongo:27017/rocketchat

ROOT_URL: http://localhost:3000

PORT: 3000

ports:

- 3000:3000

depends_on:

- mongo

volumes:

- ./uploads:/app/uploads

mongo:

image: mongo:4.4

restart: unless-stopped

volumes:

- ./data/db:/data/db

  1. Deploy via Docker Compose:

docker-compose up -d

This launches Rocket.Chat on port 3000, with MongoDB as the backend.

  1. Verify that Rocket.Chat is running:

docker ps

curl http://localhost:3000

πŸš€ Manual Installation

If you prefer a manual setup, follow these steps on a Linux server (e.g., Ubuntu 20.04):

  1. Install Node.js and MongoDB:

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

sudo apt install -y nodejs mongodb

  1. Download and extract Rocket.Chat:

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

tar -xvzf rocket.chat.tgz

cd bundle/programs/server

npm install

  1. Configure and run Rocket.Chat:

export MONGO_URL=mongodb://localhost:27017/rocketchat

export ROOT_URL=http://localhost:3000

export PORT=3000

node main.js

Rocket.Chat will now be accessible at http://<server-ip>:3000.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Set up Nginx as a reverse proxy to improve performance and allow SSL termination.

  1. Install Nginx:

sudo apt update

sudo apt install -y nginx

  1. Create an Nginx config file for Rocket.Chat (e.g., /etc/nginx/sites-available/rocketchat):

server {

server_name chat.example.com;

location / {

proxy_pass http://localhost:3000;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_set_header Host $host;

}

}

  1. Enable the configuration:

sudo ln -s /etc/nginx/sites-available/rocketchat /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your Rocket.Chat instance with Let’s Encrypt.

  1. Install Certbot:

sudo apt install -y certbot python3-certbot-nginx

  1. Obtain and apply an SSL certificate:

sudo certbot --nginx -d chat.example.com

  1. Automate certificate renewal:

sudo crontab -e

Add this line to run the renewal daily:


0 0 * * * certbot renew --quiet

πŸ› οΈ Testing and Reloading Nginx

Ensure the Nginx config is active and secure:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Rocket.Chat

πŸ—ƒοΈ Enabling Debug Logs

Increase log verbosity to debug issues effectively.

  1. Edit the container or environment variable settings:

docker exec -it <rocketchat-container-id> bash

export LOG_LEVEL=debug

  1. Restart the container to apply changes:

docker restart <rocketchat-container-id>

πŸ“„ Viewing Logs

Access logs from the Rocket.Chat container:


docker logs <rocketchat-container-id>

For manual installations, check log files in the application directory:


tail -f /path/to/rocket.chat/logs

πŸ› οΈ Troubleshooting Common Issues

If Rocket.Chat fails to start, inspect MongoDB availability:


docker exec -it <mongo-container-id> mongo --eval 'db.stats()'

Look for missing environment variables in the logs.

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup Rocket.Chat data by saving the volumes:


tar -czvf backup.tar.gz ./uploads ./data/db

πŸ”„ Database Backups

Export MongoDB data for Rocket.Chat:


docker exec <mongo-container-id> mongodump --out /data/backup

Restore it with:


docker exec <mongo-container-id> mongorestore /data/backup

πŸ“… Automated Backup Scripts

Create a cron job for periodic backups:


crontab -e

Add this line:


0 2 * * * tar -czvf /backups/backup-$(date +\%F).tar.gz /path/to/rocketchat/data

Updating and Upgrading Rocket.Chat

⬆️ Updating Docker Images

Pull the latest Rocket.Chat image and redeploy:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations:

  1. Download the latest version and repeat the manual installation steps.

πŸ” Checking for Updates

Check the Docker Hub repository for new versions:


docker search rocketchat

Leveraging Rocket.Chat’s Unique Features

πŸ”§ Enabling APIs

Rocket.Chat has a robust REST API for automation.

  1. Enable APIs in the admin panel and generate a personal access token.

  2. Test the API with curl:


curl -X GET https://chat.example.com/api/v1/info -H "X-Auth-Token: <your-token>" -H "X-User-Id: <your-user-id>"

🌟 Advanced Configurations

Integrate third-party tools like Slack-compatible webhooks:


curl -X POST -H 'Content-Type: application/json' --data '{"text": "Hello, Rocket.Chat!"}' https://chat.example.com/hooks/<webhook_id>

Wrapping Up

This guide provided a comprehensive walkthrough of installing, configuring, and managing Rocket.Chat, along with leveraging its advanced features. By following these steps, you can deploy a highly secure and customizable communication platform that gives you complete control over your data. Start implementing today and experience the full potential of Rocket.Chat for team collaboration!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.