Read in 5 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 a 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++

We also need to install Node.js and npm:

sudo yum install -y nodejs npm

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

Issue the following command 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.

We will install MongoDB using yum from the official MongoDB repositories. Open your editor of choice and create the following repository 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

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 installation, for simplicity we will name our 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 our rocket installation:

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

Install Rocket.Chat

Switch over to the rocket user:

sudo su - rocket

and 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.

Set the required environment variables with the following commands:

export PORT=3000
export ROOT_URL=http://example.com: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.63.1                          |
➔ |       NodeJS Version: 8.11.1 - x64                    |
➔ |             Platform: linux                           |
➔ |         Process Port: 3000                            |
➔ |             Site URL: http://example.com:3000/  |
➔ |     ReplicaSet OpLog: Disabled                        |
➔ |          Commit Hash: ac16e93869                      |
➔ |        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 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=http://example.com:3000/ 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; 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

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

/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;

    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 and using Rocket.Chat

Open your browser and type: http://example.com, assuming that installation is successful, you should see something like this:

Click on Register a new account, and enter your first admin login information.

Click Submit and then enter a username for your user:

Click Use this username, and you will be redirected to the homepage, logged in as an administrator.

Conclusion

You have successfully installed Rocket.Chat on CentOS 7. You can now start using Rocket.Chat to collaborate with your team. If you are facing any problem with the installation, feel free to leave a comment.