Rocket.Chat is among the most popular open source chat application that is an alternative to Slack. It comes with a couple of cool features such as file sharing, voice messages, helpdesk chat, API, video conferencing, and more.
Rocket.chat is a great option for institutions and groups that intend to host and control a chat system.
This guide will provide the key steps to deploy Rocket.Chat on an Ubuntu 18.04 VPS or dedicated server with Nginx as a reverse proxy with SSL.
Before You Start
Before you start, you’ll need the following:
- A virtual machine running on 18.04 server. You need to have at least 1GB RAM.
- A fully installed Nginx
- A domain name for your server IP address
- An SSL certificate installed
Step 1 – Installing The Dependencies
This process requires the ‘build-essential’ package to create npm packages from the source. To install this package, run the command below:
$ sudo update $ sudo apt install build-essential curl
Next, we need Node.js for the installation process, so we will install it together with the Node.js package manager, npm. To do so, run the command below:
$ sudo apt install nodejs npm
Node.js v8.9.3 version is recommended for Rocket, and it’s the latest available version at the time of writing this article.
We will also use n, which is a Node.js Package Manager (npm) package that allows the user to manage the Node.js versions available.
To install n, and the current Node.js version, run the command below:
$ sudo npm install -g inherits n $ sudo n 8.9.3
We will also need MongoDB which is a database used by Rocket.Chat to store data.
A recent version of MongoDB is available in the official Ubuntu repositories. To install it, type the command below:
$ sudo apt install mongodb
After the installation is done, MongoDB should start automatically.
Step 2 – Creating A System User
Now, create a user and group to run the RocketChat service. We will call the user rocket:
$ sudo useradd -m -U -r -d /opt/rocket rocket
Next, include the www-data user to the already created user group. Also, change the permissions of the /opt/rocket directory to enable Nginx to access the rocket installation file:
$ sudo usermod -a -G rocket www-data $ sudo chmod 750 /opt/rocket
Step 3 – Installing Rocket.Chat
Start by switching to the rocker user using the command below:
$ sudo su - rocket
To download the latest version of Rocket.Chat using curl, type the following:
$ curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tgz
After the file is downloaded, extract it then rename the directory to Rocker.Chat:
$ tar zxf rocket.chat.tgz $ mv bundle Rocket.Chat
Next, change to the directory named Rocket.Chat/programs/server then install the necessary npm packages:
$cd Rocket.Chat/programs/server $ npm install
Now, before we test whether the installation is working properly and create a systemd unit then set it up with Nginx, we need to create the necessary environment parameters then start Rocket.Chat.
$export PORT=3000 $export ROOT_URL=http://0.0.0.0:3000/ $export MONGO_URL=mongodb://localhost:27017/rocketchat
Then, change it back to the Rocket.Chat directory and run the commands below to start the Rocket.Chat server:
$cd ../../ $ node main.js
If the process is successful and there are no errors, you will see the output below:
➔ +---------------------------------------------+ ➔ | SERVER RUNNING | ➔ +---------------------------------------------+ ➔ | | ➔ | Rocket.Chat Version: 0.65.1 | ➔ | NodeJS Version: 8.9.3 - x64 | ➔ | Platform: linux | ➔ | Process Port: 3000 | ➔ | Site URL: http://0.0.0.0:3000/ | ➔ | ReplicaSet OpLog: Disabled | ➔ | Commit Hash: 8349c36de0 | ➔ | Commit Branch: HEAD | ➔ | | ➔ +---------------------------------------------+
Use the key combination CTRL+C to stop the Rocket.Chat server and proceed to the next step.
Step 4 – Creating a Systemd Unit
To ensure Rocket.Chat operates as a service, we need to build a rocket.service file that should be located in the /etc/systemd/system/ directory with the following details:
/etc/systemd/system/rocketchat.service
[Unit] Description=Rocket.Chat server After=network.target nss-lookup.target mongod.target [Service] StandardOutput=syslog StandardError=syslog SyslogIdentifier=rocketchat User=rocket Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=https://chat.example.com PORT=3000 ExecStart=/usr/local/bin/node /opt/rocket/Rocket.Chat/main.js [Install] WantedBy=multi-user.target
Now, inform systemd that a new file has been created then run the commands below to start Rocket.Chat:
$ sudo systemctl daemon-reload $ sudo systemctl start rocketchat
Check the status of the services using the command below:
$ sudo systemctl status rocketchat
You should get the following output:
● rocketchat.service - Rocket.Chat server Loaded: loaded (/etc/systemd/system/rocketchat.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2018-06-1502:53:24 PDT; 5s ago Main PID: 12543 (node) Tasks: 10 (limit: 2321) CGroup: /system.slice/rocketchat.service `-12543/usr/local/bin/node /opt/rocket/Rocket.Chat/main.js
If there are no errors so far, set the Rocket.Chat to start at boot time:
$ sudo systemctl enable rocketchat
Step 5 – Configuring Nginx as a Reverse Proxy
This tutorial assumes that you have already installed Nginx and configure it with SSL certificate.
Next, create a new server block for the Rocket.Chat service.
/etc/nginx/conf.d/chat.example.com.conf
upstream rocketchat_backend { server127.0.0.1:3000; } server { listen80; server_name chat.example.com; include snippets/letsencrypt.conf; return301 https://chat.example.com$request_uri; } server { listen443 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_trusted_certificate /etc/letsencrypt/live/chat.example.com/chain.pem; include snippets/ssl.conf; access_log /var/log/nginx/chat.example.com-access.log; error_log /var/log/nginx/chat.example.com-error.log; location / { proxy_pass http://rocketchat_backend/; proxy_http_version1.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_redirectoff; } }
Now, restart Nginx to apply these changes:
$ sudo systemctl reload nginx
Step 6 – Setting Up and Testing Rocket.Chat
Go to your web browser and enter the address: http://chat.example.com.
If the installation process is successful, you should see the Rocket.Chat service wizard. Now you can set up your user, configure your company and register your server to ensure it receives any notifications and other services.
The setup wizard will prompt you to set the Admin user as shown below:
After that, press the Continue button and you will be prompted to provide your company’s information:
The next section will require you to provide the server details:
After providing the information, press the Continue button where you will be directed to a new page showing the workspace is set and ready to use:
Press the Go to your workplace button and you should see the Rocket.Chat web interface.
Conclusion
That’s it! At the end of this guide, you should be able to install the Rocket.Chat service on Ubuntu 18.04 successfully and set up Nginx as a reverse proxy. You can also go to Rocket.Chat guide page to learn and understand the new chat system.