Atlantic.Net Blog

How to Deploy Rocket Chat with Nginx on Ubuntu 18.04

Hitesh Jethva
by Atlantic.Net (64posts) under VPS Hosting
0 Comments

Rocket.Chat is a free, open-source, self-hosted chat application that allows you to host your own chat server. It is very similar to Slack and offers similar features including file sharing, ticketing systems, video chat, and conferencing. With Rocket.Chat, you can chat with team members, create channels and private groups, make video and audio calls, share screens, and upload files.

Features

  • Powerful APIs
  • Remote video monitoring
  • Free audio and video conferencing
  • LiveChat and LDAP group sync
  • Screen and file sharing
  • Desktop and mobile notifications
  • Public and private multi-user rooms

Rocket.Chat is the best choice for you if you are looking for an open-source chat platform to host in the Cloud.

In this tutorial, we will show you how to install and configure Rocket.Chat on Ubuntu 18.04 VPS.

Prerequisites

  • A fresh Ubuntu 18.04 VPS on the Atlantic.Net Cloud Platform.
  • A valid domain name pointed to your VPS IP address. In this tutorial, we will use node1.example.com.

Note: You can refer to the Atlantic DNS Guide to manage the DNS records.

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 18.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged into your Ubuntu 18.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Node.js

Rocket.Chat requires Node.js and other dependencies for building npm packages from the source. First, add the Node.js repository by running the following command:

curl -sL https://deb.nodesource.com/setup_12.x — Node.js 12 LTS "Erbium"| bash -

Next, update the repository and install Node.js along with required dependencies with the following command:

apt-get update -y
apt-get install nodejs build-essential curl software-properties-common graphicsmagick -y

Step 3 – Install MongoDB

Rocket.Chat requires MongoDB to be installed on your server. By default, the latest version of MongoDB is not available in the Ubuntu 18.04 default repository, so you will need to add the MongoDB repository to your server.

First, download and add the official repository key with the following command:

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Next, add the MongoDB repository by running the following command:

add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'

Once the repository is added, update the repository and install MongoDB with the following command:

apt-get update -y
apt-get install mongodb-org -y

Once the MongoDB is installed, start the MongoDB service and enable it to start after system reboot:

systemctl start mongod
systemctl enable mongod

By default, MongoDB listening on port 27017. You can check it with the following command:

netstat -ant

Output:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN

Step 4 – Configure MongoDB

Rocket.Chat uses the MongoDB replica set to improve the performance, so you will need to configure the MongoDB replica set. You can configure it with the following command:

echo -e "replication:\n replSetName: \"rs01\"" | tee -a /etc/mongod.conf

Next, restart the MongoDB service to apply the changes:

systemctl restart mongod

Next, log in to MongoDB shell and initiate the replica set with the following command:

mongo
rs.initiate()

You should see the following output:

At this point, MongoDB is installed and configured with the replica set.

Type Exit to leave MongoDB.

Step 5 – Install Rocket.Chat

Before starting, it is recommended to create a new user and group to run Rocket.Chat.

First, create a new user with the name rocket with the following command:

adduser rocket

You should get the following output:

Next, allow Nginx to access the Rocket.Chat directory by adding the rocket user to www-data group:

usermod -a -G rocket www-data

Next, switch the user to rocket and download the latest version of Rocket.Chat with the following command:

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

Once the download is completed, extract the downloaded file with the following command:

tar zxf rocket.chat.tgz

Next, move the extracted directory to Rocket.Chat using the following command:

mv bundle Rocket.Chat

Next, change the directory to Rocket.Chat/programs/server directory and install all required npm packages with the following command:

cd Rocket.Chat/programs/server
npm install

Note: Rocket.Chat will take a few minutes to install

Once all the packages are installed, you should see the following output:

Next, set the required environment variables to test the Rocket.Chat installation:

export PORT=3000
export ROOT_URL=http://0.0.0.0:3000/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export MONGO_OPLOG_URL=mongodb://localhost:27017/local?replSet=rs01

Next, change the directory to Rocket.Chat and start the Rocket.Chat server using the following command:

cd ~/Rocket.Chat
node main.js

Note: This process can take several minutes to complete

You should get the following output:

Next, stop the Rocket.Chat server with CTRL+C then run the following command to exit from the rocket user:

exit

Step 6 – Create a Systemd Service File for Rocket.Chat

Next, create a systemd service file to start and stop the Rocket.Chat service:

nano /etc/systemd/system/rocketchat.service

Add the following lines:

[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 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replSet=rs01 ROOT_URL=http://node1.example.com PORT=3000
ExecStart=/usr/bin/nodejs /home/rocket/Rocket.Chat/main.js


[Install]
WantedBy=multi-user.target

Save and close the file when you are finished. Then, reload the systemd daemon with the following command:

systemctl daemon-reload

Next, start the Rocket.Chat service and enable it to start after system reboot:

systemctl start rocketchat
systemctl enable rocketchat

You can now verify the Rocket.Chat service using the following command:

systemctl status rocketchat

You should get the following output:

Step 7 – Set Up a Reverse Proxy with Nginx

Next, you will need to install and configure Nginx as a reverse proxy to forward the client requests coming on port 3000 to the Nginx port 80.

First, install the Nginx web server with the following command:

apt-get install nginx -y

Next, create an Nginx virtual host configuration file with the following command:

nano /etc/nginx/sites-available/rocket

Add the following lines:

server {
  listen 80;

  server_name    node1.example.com;
  access_log /var/log/nginx/rocket-access.log;
  error_log /var/log/nginx/rocket-error.log;

  location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:3000/;
  }
}

Save and close the file when you are finished. Then, enable the virtual host with the following command:

ln -s /etc/nginx/sites-available/rocket /etc/nginx/sites-enabled/

Finally, restart the Nginx service to apply the configuration changes:

systemctl restart nginx

Step 8 – Access Rocket.Chat Web Interface

Now, open your web browser and navigate to the URL http://node1.example.com. You will be redirected to the Rocket.Chat Setup Wizard:

Provide your admin username, email, password details and click on the Continue button. You should see the following page:

Next, provide your organization info and click on the Continue button. You should see the following page:

Next, provide your server information and click on the Continue button. You should see the following page:

Next, use Rocket.Chat’s preconfigured gateways and proxies, and click on the Continue button. You should see the following page:

Now, click on the Go to your workspace button. You will be redirected to the Rocket.Chat default dashboard:

Conclusion

Congratulations! You have successfully installed and configured Rocket.Chat server with Nginx as a reverse proxy on Ubuntu 18.04 VPS. You can visit the Rocket.Chat Doc to learn the new chat system. Get started with Rocket.Chat today on an Atlantic.Net VPS!

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources