13.8 C
Texas

How To Install Rocket Chat On Ubuntu 20.04

In this tutorial you’ll learn that how to install Rocket Chat on Ubuntu 20.04. Rocket chat is an open source platform like Slack that can be used for video meetings, group chats & integrations with many other platforms. It is self hosted chat platform so more reliable and easy to use. So, follow the below steps for an easy and optimal installation.

Step 1: Update Your System

First of all update your system.

sudo apt update -y

Step 2: Install Necessary Packages

Hit the below commands to install the required package dependencies.

- Advertisement -
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu 
focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

sudo apt -y update && sudo apt install -y curl && curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -

sudo apt install -y build-essential mongodb-org nodejs graphicsmagick

Note:Make sure to install the node version as of base version installed. If you didn’t do so, it’ll cause conflicts with the rocket chat.

You can verify the version by typing

sabi@Ubuntu20:~$ node --version
v12.20.0

Then hit the given command to install inherits & n.

sudo npm install -g inherits n

Run the below command to create symbolic link.

sudo ln -s /usr/bin/node /usr/local/bin/node

Step 3: Install Rocket Chat On Ubuntu 20.04

Run the below command to download the rocket chat package using curl.

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

Now, extract the downloaded package to the /tmp directory.

tar -xvzf /tmp/rocket.chat.tgz -C /tmp

Now, you can select where to install rocket chat. I’m going to install it under /opt folder.

cd /tmp/bundle/programs/server && npm install
sudo mv /tmp/bundle /opt/Rocket.Chat

Step 4: Create Rocket Chat System User

Fire the below commands to create new user & give owner priviliges to the rocket chat folder.

sudo useradd -M rocketchat && sudo usermod -L rocketchat
sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

Step 5: Create Rocket Chat Service

After creating the user, create rocket chat service. You can create the service unit file like below:

cat << EOF |sudo tee /etc/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
[Service]
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target
EOF

Now, hit the below commands to configure storage engine & MongoDB.

sudo sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
sudo sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf

Then, start the MongoDB services.

sudo systemctl start mongod

To start MongoDB on system boot type

sudo systemctl enable mongod

Verify:

mongo --eval "printjson(rs.initiate())"

And then start rocket chat service by typing

sudo systemctl start rocketchat

Make sure the status is in running position.

systemctl status rocketchat
● rocketchat.service - The Rocket.Chat server
Loaded: loaded (/lib/systemd/system/rocketchat.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-11-27 10:05:54 UTC; 31s ago
Main PID: 28294 (node)
Tasks: 11 (limit: 19076)
Memory: 559.7M
CGroup: /system.slice/rocketchat.service
└─28294 /usr/local/bin/node /opt/Rocket.Chat/main.js
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | MongoDB Version: 4.0.21 |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | MongoDB Engine: mmapv1 |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | Platform: linux |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | Process Port: 3000 |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | Site URL: http://0.0.0.0:3000/ |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | ReplicaSet OpLog: Enabled |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | Commit Hash: b471caf9c9 |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | Commit Branch: HEAD |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ | |
Nov 30 10:06:20 chat rocketchat[28294]: ➔ +---------------------------------------------------+

Step 6: Configuring Nginx On Ubuntu 20.04

Type the given command to install nginx.

sudo apt install nginx

Edit the /etc/nginx/conf.d/rocketchat.conf file to configure nginx with rocket chat.

sudo nano /etc/nginx/conf.d/rocketchat.conf

Then make the changes as shown below:

upstream rocket_backend {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name chat.osradar.com;
access_log /var/log/nginx/rocketchat-access.log;
error_log /var/log/nginx/rocketchat-error.log;
location / {
proxy_pass http://rocket_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;
     }
}

Note: Don’t forget to replace chat.osradar.com with your domain name.

Verify the syntax.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then restart the nginx services.

sudo systemctl restart nginx

Step 7: Setup Let’s Encrypt SSL

As for security reasons, it is recommended to use SSl with rocket chat. So, download the Let’s Encrypt SSL certificate for free.

sudo apt install certbot python3-certbot-nginx

Run the below command to get SSL.

certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Which names would you like to activate HTTPS for?

1: chat.osradar.com

Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for chat.osradar.com
Waiting for verification…
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/chat.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.

1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.

Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/chat.conf

Congratulations! You have successfully enabled
https://chat.osradar.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=chat.osradar.com

IMPORTANT NOTES:
Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/chat.osradar.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/chat.osradar.com/privkey.pem
Your cert will expire on 2021-02-26. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew all of
your certificates, run "certbot renew"
If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

After installing SSL certificates, the updated nginx file will be like this:

upstream rocket_backend {
server 127.0.0.1:3000;
}
server {
server_name chat.osradar.com;
access_log /var/log/nginx/rocketchat-access.log;
error_log /var/log/nginx/rocketchat-error.log;

location / {
proxy_pass http://rocket_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;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/chat.osradar.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/chat.osradar.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = chat.osradar.com) {
return 301 https://$host$request_uri;

} # managed by Certbot

listen 80;
server_name chat.osradar.com;
return 404; # managed by Certbot

}

Now, again verify the nginx syntax. If everything ok it’ll show the success message.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally restart nginx services.

sudo systemctl restart nginx.

Step 8: Access Rocket Chat Serve

Now, you can access your rocket chat server via FQDN with https(SSL). Configure it with the help of setup wizard as seen below:

How To Install Rocket Chat On Ubuntu 20.04

Once, done you can access the site by providing admin credentials created in the above wizard.

How To Install Rocket Chat On Ubuntu 20.04

So, this is how you can install Rocket Chat On Ubuntu 20.04

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article