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.
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.
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.
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
Start MongoDB and enable it to start at boot time using the following commands.
systemctl start mongod
systemctl enable mongod
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
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.
After installing Node.js, we will need to install few for dependencies which are
GraphicsMagick, an Image processing tool,
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.
/opt directory and download the latest version of software using the following commands.
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.
Now move back to the parent directory using the following command.
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.
your-domain.comwith 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.
Set the PORT on which Rocket.Chat will run using the following command.
You can do a quick test to check if MongoDB running using the following command.
Now the application must be accessible on port 3000. You can check by going to the following link using your favorite web browser.
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.
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
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.
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.
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.
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 *:443> ServerName yourdomain.com ServerAdmin firstname.lastname@example.org
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
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
Now head to your favorite browser and access the following URL.
You will see the following interface.
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.
Once you are registered, it will ask you to choose a username.
Now you will be automatically taken to your dashboard.
You can find the administration dashboard by clicking on the username from the left panel and finally on Administration link.
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.