Read in 6 minutes

last updated 

How to Deploy Rocket.Chat on Ubuntu 18.04

This tutorial is also available for:

centos 7

Rocket.Chat is an open source team communication platform, a self-hosted Slack alternative. It is developed using 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 a Ubuntu 18.04 server and configure Nginx as an SSL reverse proxy.

Prerequisites

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. In this article we will use chat.example.com.
  • Nginx installed, by following this tutorial .
  • You have an SSL certificate installed for your domain. You can install a free Let’s Encrypt SSL certificate by following this tutorial.

Install Dependencies

The package ‘build-essential’ is required for building some npm packages from source, to install it run the following command:

sudo update
sudo apt install build-essential curl

We also need to install Node.js and the the Node.js package manager, npm :

sudo apt install nodejs npm

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

We’re going to use n, a npm package which allows us to interactively manage our 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.9.3

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

An up-to-date version of MongoDB is included in the Ubuntu’s official repositories, to install MongoDB run the following command:

sudo apt install mongodb

Once the installation is completed, the MongoDB service will start automatically.

Create new system user

Create a new user and group, which will run our Rocket.Chat instance, for simplicity we will name our user rocket:

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 our rocket installation:

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

Install Rocket.Chat

Switch over to the rocket user:

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 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.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                  |
➔ |                                             |
➔ +---------------------------------------------+

We can now stop the Rocket.Chat server with CTRL+C 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 with the following contents:

/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 created a new unit file and start the Rocket.Chat service by executing:

sudo systemctl daemon-reload
sudo systemctl start rocketchat

You can check the service status with the the following command:

sudo systemctl status rocketchat
● rocketchat.service - Rocket.Chat server
   Loaded: loaded (/etc/systemd/system/rocketchat.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-06-15 02: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

and if there are no errors you can enable the Rocket.Chat service to be automatically started at boot time:

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 only need to create a new server block for our Rocket.Chat installation.

/etc/nginx/conf.d/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;
    }
}

Reload the Nginx service for changes to take effect:

sudo systemctl reload nginx

Configuring and using Rocket.Chat

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

Assuming that 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 organisation and registering your server to receive free push notifications and more.

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

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

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

Enter the information, click on the Continue button, and you will be redirected to the 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 Home page logged in as the admin user.

Conclusion

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.