Rocket.Chat is a fantastic chat and communication platform that’s free, open source, and contains a pretty impressive list of features. I decided to start pulling as many of my services away from large companies as possible and, after using this a few times, decided this is definitely the direction I want to go.
Prerequisites
This instruction set assumes that you have the following ready to go:
- The domain name you want to use
- An Ubuntu 16.04 server up and running
- An Apache reverse proxy (although, you could use the config here on the same server running Rocket.Chat as well)
The Prep Work
Before installing the actual Rocket.Chat application, you’ll want to do a few things first. I like to run everything as root, so these instructions are assuming you run a sudo su prior to running them. Let’s start by doing an update.
apt-get update && apt-get upgrade -y
Now let’s install the applications required to run Rocket.Chat
apt-get install curl graphicsmagick build-essential nodejs npm -y
Mongodb
I’ve never really used Mongodb before, however, it seems to just work and doesn’t require much maintenance so there’s not much to do with it. You need to start by adding the MongoDB keyserver:
apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv EA312927
Now you’ll create the list file:
echo “deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse” | tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Once that’s done, you update the Ubuntu repository:
apt-get update
And now install mongodb. I would run this without the -y so that it will prompt you to confirm install of a unauthenticated host – otherwise it will fail the install:
apt-get install mongodb-org
Once that’s installed go ahead and start and enable the service:
systemctl enable mongod
systemctl start mongod
Mongodb is now installed
Mongodb ReplicaSet
This isn’t required, but definitely recommended for the sake of better performance.
Start by editing the mongod configuration file:
vi /etc/mongod.conf
To prevent mongodb from being restricted to the localhost IP, go ahead and comment out the line 24 with a # so it should look like this:
net:
port: 27017
#bindIp: 127.0.0.1
Now you’ll add the ReplicaSet info to line 34 so it should look as follows – make sure to double space the oplog and replSetName lines or it gets pissed off for some reason:
#replication:
replication:
oplogSizeMB: 1
replSetName: rs0
Now just save and exit that file and you’re ready to restart the service.
systemctl restart mongod
Before initiating the ReplicaSet, I would go and add your hostname to your /etc/hosts file as I had issues with the initiation completing successfully before I did that. Just edit /etc/hosts and add the name of your VM to the 127.0.0.1 line.
Now you’ll initiate the ReplicaSet by entering teh MogoDB shell:
export LC_ALL=C
mongo
rs.initiate()
If that’s successful you will see this output:
{
“info2” : “no configuration specified. Using a default configuration for the set”,
“me” : “thishosting-rocks:27017”,
“ok” : 1
}
The important thing here is that the ok line is a 1. If it’s not a 1, then you need to determine what the issue is. My first run at this it gave me a 0 and that’s why I had to edit the hosts file.
npm and Node.js
Let’s start by installing the n package globally with:
npm install -g n
Now we need to install Node.js version 4.5 with:
n 4.5
Let’s check our node and npm versions with:
node –version
npm -v
As long as you see 4.5.0 and 3.5.2, you’re ready to move on.
Install Rocket.Chat
Lets start by moving to the directory that you want to install Rocket.Chat. Due to familiarity, I just put it in the /var/www directory by creating the www folder.
mkdir -p /var/www
cd /var/www
Now you’ll want to download the application with:
curl -L https://download.rocket.chat/stable -o rocket.chat.tgz
Now that it’s downloaded, go ahead and extract it:
tar -xzf rocket.chat.tgz
And now let’s rename the extracted folder:
mv bundle Rocket.Chat
Now lets go to the directory for the install:
cd /var/www/Rocket.Chat/programs/server/
Now let’s run the following in order:
npm install
cd ../../
export ROOT_URL=https://chat.domain.com
export MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs0
export PORT=3000
A couple of things to note here. First, you’ll want to change the domain to whatever it is that you’re using. Second, if you aren’t going to proxy the server, then the URL should be http://domain:port where port is the port you specify on the export PORT line and the domain is whatever it is you’re using as the domain. If that’s all successful, then you can go ahead and create a new service so that you don’t have to keep your ssh session open in order for this to work. To do so, you want to do the following:
Create a new file for the rocket.chat service:
vi /lib/systemd/system/rocketchat.service
Now add the following into the file but replacing the red fields with your own:
[Unit]
Description=rocketchat service
After=network.target
Requires=mongod.service[Service]
Type=simple
Environment=ROOT_URL=https://chat.domain.com
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs0
Environment=PORT=3000
WorkingDirectory=/var/www/Rocket.Chat/
ExecStart=/usr/local/bin/node main.js[Install]
WantedBy=multi-user.target
The values in red should match the values you entered with the export commands. Once that’s correct, save and exit the file.
Once the service is created, you can enable and start it with the following
systemctl enable rocketchat.service
systemctl start rocketchat.service
Proxy Setup
I’ve got a dedicated proxy server, however, I believe that any instance of Apache will work with this. I’m also using letsencrypt for the SSL certs and that’s been working great.
vi /etc/httpd/conf.d/chat.domain.net-ssl.conf
Now within the file you’ll want to put the following:
<IfModule mod_ssl.c>
<VirtualHost *:443>ServerName chat.domain.net
RewriteEngine on
SSLProxyEngine On
ProxyPreserveHost On
ProxyPass / http://10.10.2.38:3000/
ProxyPassReverse / http://chat.domain.com:3000/# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.# RewriteCond %{SERVER_NAME} =chat.domain.net
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]SSLCertificateFile /etc/letsencrypt/live/chat.domain.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/chat.domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/chat.domain.com/chain.pem
</VirtualHost>
</IfModule>
This will allow you to just enter a domain name and not have to put the port at the end.
Other Features
There are a LOT of other features you can incorporate into Rocket.Chat, one of which is a livechat feature integrated with wordpress. I won’ go into the details on it, but at the end of this article he discusses what’s needed to do that. It looks pretty straightforward to do if you’re so inclined.