Rocket.Chat is an open-source team communication platform, a self-hosted Slack alternative. It is developed using the Meteor framework and provides various features including helpdesk chat, file sharing, video conferencing, voice messages, API, and more.

Rocket.Chat is a perfect solution for companies and communities that want to host their own chat system.

In this tutorial, we will show you how to deploy Rocket.Chat on an Ubuntu 18.04 server and configure Nginx as an SSL reverse proxy.

Before proceeding with this tutorial, make sure that you have the following prerequisites.

Ubuntu 18.04 server. According to the official Rocket.Chat system requirements you need at least 1G of RAM.

A domain name pointing to your server IP address. We will use chat.example.com .

. Nginx installed, by following this tutorial .

You have an SSL certificate installed for your domain. You can generate a free Let’s Encrypt SSL certificate by following this tutorial .

Start by updating your system packages list:

sudo apt update

Install Node.js, npm and all other dependencies required for building npm packages from source:

sudo apt install nodejs npm build-essential curl software-properties-common graphicsmagick

At the time of writing this article, the recommended Node.js version for Rocket.Chat is Node.js v8.11.3.

We’re going to use n , a npm package which allows us to interactively manage the Node.js versions.

Issue the following commands to install n and the recommended Node.js version:

sudo npm install -g inherits n sudo n 8.11.3

Installing MongoDB #

MongoDB is a NoSQL document-oriented database and it is used by Rocket.Chat as a data store.

We will install MongoDB from the official MongoDB repositories.

Import the MongoDB public key and enable the official MongoDB repository with the following command:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'

Once the apt repository is enabled update the packages list and install MongoDB by typing:

sudo apt update sudo apt install mongodb-org

Once the installation is completed, enable and start the MongoDB service:

sudo systemctl start mongod sudo systemctl enable mongod

Create new System User #

To create a new user and group named rocket , that will run the Rocket.Chat instance, type:

sudo useradd -m -U -r -d /opt/rocket rocket

Add the www-data user to the new user group and change the /opt/rocket directory permissions so that the Nginx can access the Rocket.Chat installation:

sudo usermod -a -G rocket www-data sudo chmod 750 /opt/rocket

Change over to the user rocket :

sudo su - rocket

The following commands assume that you are currently operating as user rocket .

Download the latest stable version of Rocket.Chat with curl :

curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tgz

Once the download is completed extract the archive and rename the directory to Rocket.Chat :

tar zxf rocket.chat.tgz mv bundle Rocket.Chat

Change into the Rocket.Chat/programs/server directory and install all required npm packages:

cd Rocket.Chat/programs/server npm install

In order to test our installation before creating systemd unit and setting up a reverse proxy with Nginx we will set the required environment variables and start the Rocket.Chat server

export PORT=3000 export ROOT_URL=http://0.0.0.0:3000/ export MONGO_URL=mongodb://localhost:27017/rocketchat

Change back into the Rocket.Chat directory and start the Rocket.Chat server by issuing the following commands:

cd ../../ node main.js

If there are no errors you should see the following output:

➔ +---------------------------------------------+ ➔ | SERVER RUNNING | ➔ +---------------------------------------------+ ➔ | | ➔ | Rocket.Chat Version: 0.71.1 | ➔ | NodeJS Version: 8.11.3 - x64 | ➔ | Platform: linux | ➔ | Process Port: 3000 | ➔ | Site URL: http://0.0.0.0:3000/ | ➔ | ReplicaSet OpLog: Disabled | ➔ | Commit Hash: e73dc78ffd | ➔ | Commit Branch: HEAD | ➔ | | ➔ +---------------------------------------------+

Stop the Rocket.Chat server with CTRL+C .

Switch back to your sudo user by typing exit and continue with the next steps.

Create a Systemd unit #

To run Rocket.Chat as a service we will create a rocketchat.service unit file in the /etc/systemd/system/ directory.

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

Paste the following content:

/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

Notify systemd that we have created a new unit file and start the Rocket.Chat service by executing:

sudo systemctl daemon-reload sudo systemctl start rocketchat

Check the service status by typing:

sudo systemctl status rocketchat

* rocketchat.service - Rocket.Chat server Loaded: loaded (/etc/systemd/system/rocketchat.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2018-11-07 14:36:24 PST; 5s ago Main PID: 12693 (node) Tasks: 10 (limit: 2319) CGroup: /system.slice/rocketchat.service `-12693 /usr/local/bin/node /opt/rocket/Rocket.Chat/main.js

Finally, enable the Rocket.Chat service to be automatically started at boot time with the following command:

sudo systemctl enable rocketchat

Set up a reverse proxy with Nginx #

If you followed our how to install Nginx on Ubuntu 18.04 and how to secure Nginx with Let’s Encrypt on Ubuntu 18.04 guides you should already have Nginx installed and configured with SSL certificate.

Now we need to create a new Nginx server block for the Rocket.Chat installation.

Open your text editor and create the following file:

sudo nano /etc/nginx/sites-available/chat.example.com.conf

/etc/nginx/sites-available/chat.example.com.conf

upstream rocketchat_backend { server 127.0.0.1 : 3000 ; } server { listen 80 ; server_name chat.example.com ; include snippets/letsencrypt.conf ; return 301 https://chat.example.com $request_uri ; } server { listen 443 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_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 ; } }

Enable the new server block by creating a symbolic link from the file to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/chat.example.com.conf /etc/nginx/sites-enabled/

Reload the Nginx service for changes to take effect:

sudo systemctl reload nginx

Open your browser and type: http://chat.example.com .

Assuming that the installation is successful, you’ll be presented with the Rocket.Chat Setup Wizard which will guide you through setting up your first admin user, configuring your organization and registering your server to receive free push notifications and more.

The first section of the Initial Setup wizard will ask you to set up your Admin user:

Once you are done entering the Admin info click on the Continue button and in the next step enter your organization info:

The third section of the Initial Setup wizard will prompt you to enter the server information:

In the next step, you will be asked whether you want to use the Rocket.Chat’s preconfigured gateways and proxies. Selecting this option will give you access to the Rocket.Chat Apps marketplace and other features such as push notifications will work out of the box.

Make your choice, click on the Continue button, and you will be redirected to the following page indicating that your workspace is ready to use:

Click on the Go to your workspace button and you will be redirected to the Rocket.Chat dashboard logged in as the admin user.

In this tutorial, you learned how install Rocket.Chat on Ubuntu 18.04 and how to setup Nginx as a reverse proxy.

You should now visit the Rocket.Chat Documentation page and learn more about your new chat system.

If you are facing any problem with the installation, feel free to leave a comment.