Rocket.Chat is an open source web chat server. It is written in JavaScript and uses the Meteor full stack framework. It is a super feature rich alternative for Slack providing video conferencing, group chat, direct messaging, help desk chat, file sharing, voice messages, link previews and a full featured API. It provides you full control over your chats and communications. It also provides client applications for Windows, Mac, Linux. Mobile applications for Android and iOS are also provided.
In this tutorial, we will install Rocket.Chat server on CentOS 7 after installing all the required dependencies. We will also setup Apache as a reverse proxy using Let’s Encrypt SSL.
Requirements
Rockt.Chat requires at least 1GB RAM and Single Core CPU to install, which is enough to server 200 users and 50 active users with activities. To serve more users you will need more resources like to server up to 1000 users and 300 active connection you will need to 6 Core CPU and 4GB RAM. To follow this tutorial you will need a server with minimal CentOS 7 installed. You will also need root access to the server, if you are logged in as non root user, run sudo -i
to login in as root user. A domain pointing to your server is also required.
Install Rocket.Chat Server
Before installing any package it is recommended to update the server and available packages. Run the following command to do so.
yum -y update
Rocket.Chat requires few dependencies that are not included in YUM repository thus you will need to install the EPEL repository also.
yum -y install epel-release
yum -y update
You can now restart your server so that the updates can take effect.
Installing MongoDB
Rocket.Chat uses MongoDB to store its data. MongoDB community version is not found on the YUM or EPEL repository hence you need to install the MongoDB repository. Create a new repo file using the following command.
nano /etc/yum.repos.d/mongodb-org.repo
If you don’t have nano installed, you can install it using yum -y install nano
. Paste the following lines into the file and save the file and exit the editor using CTRL-O followed by CTRL-X.
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Now you can install MongoDB using the following command.
yum -y install mongodb-org
The above command will install four packages named mongodb-org-server
, mongodb-org-mongos
, mongodb-org-shell
and mongodb-org-tools
.
Start MongoDB and enable it to start at boot time using the following commands.
systemctl start mongod
systemctl enable mongod
Once you have installed MongoDB, you will need to install Node.js as Rocket.Chat is written in JavaScript.
Installing Node.js
To install Node.js with NPM or Node Package Manager, run the following command.
yum -y install nodejs npm
Now you will need to install inherits
and n
package so that we can install the desired version of Node.js. Run the following command for same.
npm install -g inherits n
Once Node.js is installed, you will need to install Node.js version 4.5 as Rocket.Chat needs Node.js version 4.5 to run properly.
n 4.5
After installing Node.js, we will need to install few for dependencies which are GraphicsMagick
, an Image processing tool, curl
and gcc-c++
. Run the following command for same.
yum -y install curl GraphicsMagick gcc-c++
Now that we have all the dependencies ready, we can now install Rocket.Chat.
Installing Rocket.Chat
Move to /opt
directory and download the latest version of software using the following commands.
cd /opt
curl -L https://rocket.chat/releases/latest/download -o rocket.chat.tgz
Extract the files using the following command.
tar zxvf rocket.chat.tgz
The above command will extract the files in a directory named bundle
. Change the name of the directory using the following command.
mv bundle Rocket.Chat
Now switch to the installation directory and install the software using the following command.
cd Rocket.Chat/programs/server
npm install
Now move back to the parent directory using the following command.
cd /opt/Rocket.Chat
Now you will need to set some Global Variables so that Rocket.Chat can use them where required. Set the Root URL of the application using the following command.
export ROOT_URL=https://your-domain.com/
Replace your-domain.com
with your actual domain. We have used https
as we are going to set up an SSL secured reverse proxy with Apache. Set MongoDB URL using the following command.
export MONGO_URL=mongodb://localhost:27017/rocketchat
Set the PORT on which Rocket.Chat will run using the following command.
export PORT=3000
You can do a quick test to check if MongoDB running using the following command.
node main.js
Now the application must be accessible on port 3000. You can check by going to the following link using your favorite web browser.
http://yourdomain.com:3000
To stop the application, press Ctrl + C.
Creating Systemd Service
Now we will need to create a Systemd service so that it can be started and stopped as service.
To create the systemd service file, run the following command.
nano /etc/systemd/system/rocketchat.service
Copy and paste the following contents in the file.
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target mongod.target
[Service]
Type=simple
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=root
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://yourdomain.com PORT=3000
[Install]
WantedBy=multi-user.target
Make sure that you change the ROOT_URL
parameter in the above lines to your actual domain. Save the file and exit from the editor.
You can now start the application using the following command.
systemctl start rocketchat
To enable the application to automatically start at boot time run the following command.
systemctl enable rocketchat
You can check the status of the service using the following command.
systemctl status rocketchat
Configuring Apache as Reverse Proxy with Let’s Encrypt SSL
Install Apache web server and mod_ssl
using the following command.
yum -y install httpd mod_ssl
Now start Apache web server and enable it to automatically start at boot time using the following commands.
systemctl start httpd
systemctl enable httpd
Now we will need to generate SSL certificates from Let’s Encrypt client. To install Let’s Encrypt client also called Certbot, run the following command.
yum -y install python-certbot-apache
Once the installation finishes, run the following command to obtain the SSL certificates from Let’s Encrypt. Make sure that your domain is pointed to the server, the Let’s Encrypt will check the domain authority before providing the certificates.
certbot certonly --apache -d yourdomain.com
This command will run Let’s Encrypt client to obtain the certificates only but not to install it. --apache
tells the client to use Apache web server for authentication of domain authority. -d yourdomain.com
tells the domain name for which the certificates needs to be obtained. It may ask you which SSL configuration to use during authentication, choose ssl.conf
. All the changes made to the file will be automatically restored. Finally provide your email address and accept the terms and condition. Once the certificates are generated, they are likely to be stored in the following directory.
/etc/letsencrypt/live/yourdomain.com
Where yourdomain.com
is your actual domain. In the directory, you will find cert.pem
which is your domains certificate and privkey.pem
which is your certificate’s private key.
Let’s Encrypt SSL expires in 90 days, so it is recommended to set an automatic renewal for your certificates. Run the following command to open your crontab file.
crontab -e
Enter the following line into the crontab file.
30 1 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log
The above cron job will automatically run every monday at 1:30 AM and if your certificates are due for expiry, it will automatically renew them.
As our SSL certificates are now generated, we can proceed further to configure httpd configuration file. Create a new virtual host file using the following command.
nano /etc/httpd/conf.d/yourdomain.com.conf
Replace yourdomain.com
with your actual domain. Now copy and paste the following lines into the file.
<VirtualHost *:80>
ServerName yourdomain.com
Redirect permanent / https://yourdomain.com/
TransferLog /var/log/httpd/yourdomain.com_access.log
ErrorLog /var/log/httpd/yourdomain.com_error.log
</VirtualHost>
<VirtualHost *:443>
ServerName yourdomain.com
ServerAdmin me@liptanbiswas.com
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
ProxyPreserveHost On
ProxyPassMatch ^/sockjs/(.*)/websocket ws://localhost:3000/sockjs/$1/websocket
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
TransferLog /var/log/httpd/yourdomain.com_ssl_access.log
ErrorLog /var/log/httpd/yourdomain.com_ssl_error.log
</VirtualHost>
In the above configuration change yourdomain.com
to your actual domain. Also, make sure that the path to your SSL certificate and private key are correct. Once done, you will have to restart your Apache server so that the changes made can take effect.
systemctl restart httpd
Adjust SELinux so that it can connect to the port 3000 using the following command.
setsebool -P httpd_can_network_connect true
Now you can start the Rocket.Chat service if not started already using the following command.
systemctl start rocketchat
Accessing Rocket.Chat
Now head to your favorite browser and access the following URL.
https://yourdomain.com
You will see the following interface.
HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/1802857670.jpg” alt=”” />
Click on Register a new account and register yourself by entering your name, email and password. The first user to register is automatically promoted to the Administrator.
HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/967873840.png” alt=”” />
Once you are registered, it will ask you to choose a username.
HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/1449641774.png” alt=”” />
Now you will be automatically taken to your dashboard.
HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/1336386051.jpg” alt=”” />
You can find the administration dashboard by clicking on the username from the left panel and finally on Administration link.
HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/378160807.png” alt=”” />
Conclusion
In this tutorial, we have learned how to install Rocket.Chat on CentOS 7 Server. You can now deploy the application on your own server to collaborate and communicate in your office to increase the productivity.