If you are searching for an open-source self-hosted chat platform then Rocketchat can be the best option. Rocket chat can be used as an alternative to different communication channels such as slack, mattermost etc. Rocket chat comes with different features such as group chats, video conferencing, and you can integrate live chat with other platforms. In this article, we will learn how to set up a self-hosted Rocketchat system with let’s encrypt SSL certificates.
Prerequisites
- Fresh ubuntu server
- Root access or sudo privileged account
- A domain name pointed with server IP
- Internet connection to download applications
Install required packages and dependencies
Before installing the packages, update the Ubuntu system using the following command
$ sudo apt-get update -y
Once the system update is completed, configure apt to install MongoDB packages using the following command.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Output :
To configure Node.js to be able to install using apt package manager run the following command.
$ sudo apt-get -y update && sudo apt-get install -y curl && curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -
Output:
Now install the build tools Nodejs, MongoDB, and graphicsmagick :
$ sudo apt-get install -y build-essential mongodb-org nodejs graphicsmagick
Output :
Now install inherits and n, and the node version required by Rocketchat.
$ sudo npm install -g inherits n && sudo n 12.18.4
To check the version of Nodejs installed, run the following command.
$ node --version
Output:
v12.18.4
Install Rocketchat
We have already installed the required dependencies. Now in this step, we will download the Rocket Chat application and install it on Ubuntu 20.04.
Download the latest version of Rocketchat using the following command.
$ curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
tar -xzf /tmp/rocket.chat.tgz -C /tmp
Output :
Extract the downloaded application. You can choose your preferable directory to store the extracted file. In this example, I have extracted the file in the /tmp directory.
$ tar -xvzf /tmp/rocket.chat.tgz -C /tmp
Now install Rocketchat. In this article /opt directory is used for installation. You can prefer any directory.
$ cd /tmp/bundle/programs/server && npm install
Output:
$ sudo mv /tmp/bundle /opt/Rocket.Chat
Configure the Rocket.Chat service
Create a rocketchat user, set the correct permission to the Rocket.Chat application directory and create Rocket.Chat service.
$ sudo useradd -M rocketchat && sudo usermod -L rocketchat
$ sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
To create rocketchat.service, run the following command on your terminal
catExample:
Now we need to set up a MongoDB storage engine and replication. After this, enable and start mongoDB as:
$ sudo sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf$ sudo sed -i "s/^#replication:/replication:n replSetName: rs01/" /etc/mongod.conf$ sudo systemctl enable mongod && sudo systemctl start mongod$ mongo --eval "printjson(rs.initiate())"Output :
Now start and enable Rocket.Chat service using the following command:
$ sudo systemctl enable rocketchat && sudo systemctl start rocketchatVerify the Rocket.Chat service status”
$ sudo systemctl status rocketchatOutput:
Nginx installation and Reverse proxy configuration
To configure nginx reverse proxy for Rocket.Chat, install nginx using the following command
$ sudo apt install nginxCreate nginx virtual host configuration for rocketchat.
$ sudo nano /etc/nginx/conf.d/rocketchat.confNow paste the following contents and save the file
upstream backend { server 127.0.0.1:3000; } server { listen 80; server_name your_rocketchat_domain_name; access_log /var/log/nginx/rocket.chat.access.log; error_log /var/log/nginx/rocket.chat.error.log; location / { proxy_pass http://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; } }Check the nginx configuration file
$ sudo nginx -t
Restart and enable nginx service
$ sudo systemctl restart nginx$ sudo systemctl enable nginxNow access your rocketchat domain as
You will get web setup wizard, complete it and start using Rocket.Chat
Nginx as SSL reverse proxy
We configured Rocket.Chat with only HTTP reverse proxy. To configure nginx as an SSL reverse proxy you will need certificate files. Edit the nginx vhost file and paste the following contents.
$ sudo nano /etc/nginx/conf.d/rocketchat.confupstream backend { server 127.0.0.1:3000; } server { listen 443 ssl; Server_name your_rocketchat_domain_name; client_max_body_size 200M; access_log /var/log/nginx/rocket.chat.access.log; error_log /var/log/nginx/rocket.chat.error.log; ssl_certificate /etc/nginx/certificate.crt; ssl_certificate_key /etc/nginx/private.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; location / { proxy_pass http://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-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Nginx-Proxy true; proxy_redirect off; }Note :
Generate or purchase ssl certificate and point the directory of your certificate file in the following configuration parameter.
ssl_certificate /etc/nginx/certificate.crt; [Your certificate file]ssl_certificate_key /etc/nginx/private.key; [Your Private Key file]Check the nginx configuration file
sudo nginx -tRestart nginx service
sudo systemctl restart nginxAccessing Rocketchat
Once the reverse proxy is configured, you can access your Rocket.Chat using the URL as:
https://you_rocket_chat_domain
You will get Rocket.Chat web setup wizard. Complete the setup and start using your self-hosted Rocket.Chat.
Conclusion
In this article, we have learned how to install and configure self-hosted Rocket chat on Ubuntu 20.04. Also, I have covered how to install and configure nginx for reverse proxy with let’s encrypt SSL certificates.