Read in 6 minutes

last updated 

How to deploy Rocket.Chat on CentOS 7

Rocket.Chat is a complete team communication platform, a self-hosted Slack alternative. It is built with Meteor and provides various features including helpdesk chat, video conferencing, file sharing, voice messages, API, and more.

In this tutorial, we will show you how to install and deploy Rocket.Chat on a CentOS 7 server with Nginx as an SSL reverse proxy.

Prerequisites

Make sure that you have meet the following prerequisites before continuing with this tutorial:

  • CentOS 7 server, according to the official Rocket.Chat system requirements you need at least 1G of RAM.
  • You are logged in as a user with sudo privileges.
  • You have a domain name pointing to your server IP address. In this article we will use example.com.
  • You have Nginx installed, if not you can install it by following this tutorial.
  • An SSL certificate. You can generate a free one from Let’s Encrypt, or buy one from another provider.

Install Dependencies

Install the following packages which are necessary to build the required npm modules:

sudo yum install epel-release curl GraphicsMagick gcc-c++

Next, install Node.js and npm by typing:

sudo yum install -y nodejs npm

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

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

sudo npm install -g inherits n
sudo n 8.11.3

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

We will install MongoDB using yum from the official MongoDB repositories.

Open your editor of choice and create the following repository file:

sudo nano /etc/yum.repos.d/mongodb-org.repo

Paste the following content into the file:

/etc/yum.repos.d/mongodb-org.repo
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

Save the file and close your text editor.

To install MongoDB, run the following command:

sudo yum 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

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

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

Add the nginx user to the new user group and change the /opt/rocket directory permissions so that the Nginx can access it:

sudo usermod -a -G rocket nginx
sudo chmod 750 /opt/rocket

Installing Rocket.Chat

Switch to the rocket user by typing:

sudo su - 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 the required npm packages:

cd Rocket.Chat/programs/server
npm install

Before creating systemd unit and setting up a reverse proxy with Nginx it is a good idea to test if the installation was successful.

To do so, start by setting the required environment variables:

export PORT=3000
export ROOT_URL=http://example.com:3000/
export MONGO_URL=mongodb://localhost:27017/rocketchat

Next, 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                  |
➔ |                                             |
➔ +---------------------------------------------+

At this point, Rocket.Chat is installed on your CentOS 7 machine. 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 create a rocketchat.service unit file in the /etc/systemd/system/ directory:

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

Paste the following content into the file:

/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=http://example.com:3000/ PORT=3000
ExecStart=/usr/local/bin/node /opt/rocket/Rocket.Chat/main.js

[Install]
WantedBy=multi-user.target

Save and close the file.

Notify systemd that a new unit file was creates and start the Rocket.Chat service by executing:

sudo systemctl daemon-reload
sudo systemctl start rocketchat

Check the service status with the the following command:

sudo systemctl status rocketchat

The output should look something like this:

● rocketchat.service - Rocket.Chat server
   Loaded: loaded (/etc/systemd/system/rocketchat.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-04-10 20:30:56 UTC; 8s ago
 Main PID: 32356 (node)
   CGroup: /system.slice/rocketchat.service
           └─32356 /usr/local/bin/node /opt/rocket/Rocket.Chat/main.js

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 CentOS 7 and how to secure Nginx with Let’s Encrypt on CentOS 7 guides you should already have Nginx installed and configured with SSL certificate.

Now we need to create a new server block for our Rocket.Chat installation:

sudo nano /etc/nginx/conf.d/example.com.conf

Paste the following content into the file:

/etc/nginx/conf.d/example.com.conf
upstream rocketchat_backend {
  server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name example.com www.example.com;

    include snippets/letsencrypt.conf;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/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 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:

On 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 most of other features such as push notifications will just work out of the box.

Make you choice, 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 dashboard logged in as the admin user.

Conclusion

You have successfully installed Rocket.Chat on your CentOS 7 server. You can now start using Rocket.Chat to collaborate with your team, share files and chat in real time.

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