Come hang with us on Discord and chat directly with the team!Discordtop-bar-close-icon

2024-08-26

Complete Guide: How to Install RocketChat on Ubuntu 22.04 with Nginx

tutorials
img

Are you looking for a powerful, open-source communication platform for your team or organization? Look no further! This comprehensive guide will walk you through the process of installing RocketChat on Ubuntu 22.04, using Nginx as a reverse proxy. Whether you're an IT professional or a tech enthusiast, this step-by-step tutorial will help you set up your own RocketChat server in no time.

Why Choose RocketChat?

1. Open-Source: Fully customizable to fit your needs
2. Real-Time Communication: Instant messaging and collaboration
3. Flexibility: Host on your own servers for complete control
4. High Security: Strong data protection standards
5. Scalability: Grows with your organization

Prerequisites

Before we begin, make sure you have:

- A VPS running Ubuntu 22.04
- Root access or a user with sudo privileges
- A domain name pointed to your server's IP address

Step-by-Step Installation Guide

Step 1: Update Your System

First, let's ensure your Ubuntu system is up-to-date:


sudo apt-get update -y && sudo apt-get upgrade -y
 

Step 2: Install Nginx

Install the Nginx web server:


sudo apt install nginx -y
sudo systemctl start nginx && sudo systemctl enable nginx
 

Verify Nginx is running:


systemctl status nginx
 

Step 3: Install MongoDB

Add the MongoDB repository and GPG key:


wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc |  gpg --dearmor | sudo tee /usr/share/keyrings/mongodb.gpg > /dev/null
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
 

Install MongoDB:


sudo apt update
sudo apt install mongodb-org
sudo systemctl start mongod && sudo systemctl enable mongod
 

Verify MongoDB is running:


sudo systemctl status mongod
 

Step 4: Install RocketChat

Download and extract RocketChat:


curl -L https://releases.rocket.chat/latest/download -o /opt/rocket.chat.tgz
tar -xzf /opt/rocket.chat.tgz -C /opt
mv /opt/bundle/ /opt/RocketChat
cd /opt/RocketChat/programs/server
npm install
 

Step 5: Create the RocketChat Service

Create a system user for RocketChat:


sudo useradd -M rocketchat && sudo usermod -L rocketchat
sudo chown -R rocketchat:rocketchat /opt/RocketChat
 

Configure MongoDB storage:


sudo sed -i "s/^#  engine:/  engine: wiredTiger/"  /etc/mongod.conf
sudo sed -i "s/^#replication:/replication:\n  replSetName: rs01/" /etc/mongod.conf
 

Create and configure the RocketChat service file:


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

Add the following content:

ini
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
ExecStart=/usr/bin/node /opt/RocketChat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target
 

Start and enable the RocketChat service:


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

Step 6: Configure Nginx as a Reverse Proxy

Create an Nginx configuration file for RocketChat:


sudo nano /etc/nginx/sites-enabled/rocketchat.conf
 

Add the following content (replace YourDomainNameHere with your actual domain):


server {
  listen 80;
  server_name YourDomainNameHere;
  access_log /var/log/nginx/rocket_access.log;
  error_log /var/log/nginx/rocket_error.log;

  location / {
    proxy_pass http://127.0.0.1:3000/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forward-Proto http;
    proxy_set_header X-Nginx-Proxy true;
  }
}
 

Check Nginx configuration and restart:


nginx -t
sudo systemctl restart nginx
 

Congratulations!

You've successfully installed RocketChat on your Ubuntu 22.04 server with Nginx as a reverse proxy. Access your new RocketChat instance at `http://YourDomainName` and follow the on-screen instructions to set up your organization.

Pro Tips for RocketChat Success

1. Security First: Implement SSL/TLS encryption for secure communications.
2. Regular Backups: Set up automated backups of your RocketChat data and configurations.
3. Stay Updated: Keep your RocketChat installation, Ubuntu system, and all components up-to-date.
4. Monitoring: Implement server monitoring to ensure smooth operation and quick problem resolution.

By following this guide, you've taken a significant step towards enhancing your team's communication and collaboration capabilities. RocketChat's powerful features, combined with the stability of Ubuntu 22.04 and the performance of Nginx, create an unbeatable combination for modern organizations.

Remember, the world of open-source communication platforms is ever-evolving. Stay engaged with the RocketChat community, explore new features, and customize your instance to make the most of this powerful tool.

Happy chatting with RocketChat on Ubuntu 22.04!