In today’s guide, we will discuss how to Install Rocket.Chat Server on Debian 10|Ubuntu 18.04. Rocket.Chat is a self-hosted chat platform that is open source and one of the most popular slack alternatives. Some cool features that come with Rocket.Chat free installation are file sharing, video conferencing, chats, audio messaging e.t.c. If you’re looking for an open-source messaging platform to host in a VPS running in the Cloud or your local data center, this solution is fit for you.
In this article, we will explain the complete steps required to Install and Configure Rocket.Chat Server on Debian 10 / Ubuntu 18.04. We will use the following tools during setup:
- Nginx webserver
- Let’s Encrypt SSL certificate
- Node.js
- MongoDB
If your server is on a private network, you can generate and use a self-signed certificate in place of Let’s Encrypt. This is more recommended as opposed to running Rocket.Chat server on plain http.
Launch a terminal on either server to get started.
Step 1: Update System
Start by updating all system packages on Ubuntu / Debian Linux server.
sudo apt -y update
sudo apt -y upgrade
Reboot the system after update/upgrade.
sudo shutdown -r now
Step 2: Install Required Dependencies
Here we will install all the dependencies required to run Rocker.Chat on Debian / Ubuntu server.
sudo apt update
sudo apt install -y build-essential curl software-properties-common npm nginx graphicsmagick
Install Node.js
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt-get install -y nodejs
Confirm node version.
$ node --version
v14.21.3
Install MongoDB.
On Ubuntu 18.04:
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-6.gpg
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update
sudo apt -y install mongodb-org
sudo systemctl enable --now mongod
On Debian 10:
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-6.gpg
echo "deb http://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update
sudo apt -y install mongodb-org
sudo systemctl enable --now mongod
Step 3: Download and Install Rocket.Chat
Download the latest Rocket.Chat version:
curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tgz
Extract downloaded archive file.
tar xvf rocket.chat.tgz
Install Rocket.Chat server
cd bundle/programs/server
npm install
Move the bundle directory to /srv/rocket folder
$ cd ../../..
$ sudo mv bundle /opt/Rocket.Chat
$ ls -lh /opt/Rocket.Chat
total 20K
-r--r--r-- 1 1001 116 535 Dec 5 20:59 README
-r--r--r-- 1 1001 116 192 Dec 5 20:59 main.js
drwxr-xr-x 5 1001 116 4.0K Dec 5 21:01 programs
drwxr-xr-x 2 1001 116 4.0K Dec 5 20:59 server
-r--r--r-- 1 1001 116 605 Dec 5 21:01 star.json
Step 3: Create rocketchat system user
We need a user that will be used to run Rocket.Chat server. Create one by running below commands.
sudo useradd -M rocketchat && sudo usermod -L rocketchat
Make sure the ownership of the folder is correct.
sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
Step 5: Create Systemd Unit file
We can now create a Systemd service unit file.
cat << EOF |sudo tee /etc/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target mongod.target
[Service]
ExecStart=/usr/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target
EOF
If you’re using a valid domain in DNS, set it on ROOT_URL. example:
ROOT_URL=http://rocket.example.com
Update systemd units and start rocketchat service.
sudo systemctl daemon-reload
sudo systemctl restart rocketchat
Confirm service status
$ systemctl status rocketchat.service
● rocketchat.service - The Rocket.Chat server
Loaded: loaded (/etc/systemd/system/rocketchat.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2019-07-20 09:38:14 CEST; 8s ago
Main PID: 11264 (node)
Tasks: 10 (limit: 4915)
CGroup: /system.slice/rocketchat.service
└─11264 /usr/local/bin/node /srv/rocket/Rocket.Chat/main.js
Jul 20 09:38:14 ubuntu18 systemd[1]: Started The Rocket.Chat server.
Screenshot.
Don’t forget to enable Rocket.Chat service to Start at boot.
sudo systemctl enable rocketchat
Step 6: Configure Nginx Reverse proxy
We can now create an Nginx configuration file for Rocket.Chat
sudo nano /etc/nginx/conf.d/rocketchat.conf
Without SSL:
upstream rocket_backend {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name rocketchat.example.com;
access_log /var/log/nginx/rocketchat-access.log;
error_log /var/log/nginx/rocketchat-error.log;
location / {
proxy_pass http://rocket_backend/;
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;
proxy_redirect off;
}
}
With Let’s Encrypt SSL:
# Upstreams
upstream rocket_backend {
server 127.0.0.1:3000;
}
# HTTP server with redirect to https
server {
listen 80;
server_name rocket.example.com;
return 301 https://rocket.example.com$request_uri;
}
server {
listen 443 ssl http2;
server_name rocket.example.com;
# Configure SSL
ssl_certificate /etc/letsencrypt/live/rocket.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/rocket.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/rocket.example.com/chain.pem;
include snippets/ssl.conf;
# Logging
access_log /var/log/nginx/rocketchat-access.log;
error_log /var/log/nginx/rocketchat-error.log;
location / {
proxy_pass http://rocket_backend/;
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;
proxy_redirect off;
}
}
Quickly get Let’s Encrypt SSL
wget https://dl.eff.org/certbot-auto
sudo mv certbot-auto /usr/local/bin/
sudo chmod a+x /usr/local/bin/certbot-auto
export DOMAIN="chat.domain.com"
export EMAIL_ALERT="[email protected]"
/usr/local/bin/certbot-auto certonly --standalone -d $DOMAIN \
--preferred-challenges http --agree-tos -n -m $EMAIL_ALERT --keep-until-expiring
Check configuration syntax:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Start and enable Nginx service.
sudo systemctl restart nginx
sudo systemctl enable nginx.service
Service status should be “running“.
$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-07-20 09:51:21 CEST; 5s ago
Docs: man:nginx(8)
Process: 11510 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 11521 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 11511 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 11534 (nginx)
Tasks: 3 (limit: 4915)
CGroup: /system.slice/nginx.service
├─11534 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─11535 nginx: worker process
└─11536 nginx: worker process
Jul 20 09:51:21 ubuntu18 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 20 09:51:21 ubuntu18 systemd[1]: Started A high performance web server and a reverse proxy server.
Visit Rocket.Chat URL on http://rocket.example.com and follow next prompts to finish the installation.
Install Zulip Chat Server on Ubuntu / Debian
How to Install Openfire XMPP chat server on Ubuntu