Tutorial

How To Install, Configure, and Deploy Rocket.Chat on Ubuntu 14.04

Published on March 7, 2016
How To Install, Configure, and Deploy Rocket.Chat on Ubuntu 14.04

Introduction

Rocket.Chat is an open-source messaging app built with Meteor. It supports video conferencing, file sharing, voice messages, has a fully-featured API, and more. Rocket.Chat is great for those who prefer to have full control over their communications.

In this tutorial, we will be installing and configuring Rocket.Chat on a fresh Ubuntu server as well as setting up a reverse proxy via Nginx to boost security and make accessing Rocket.Chat much easier. Once we’re finished, you’ll have a functional instance of Rocket.Chat accessible from virtually anywhere.

Prerequisites

To follow this tutorial, you will need:

Step 1 — Installing Dependencies

In this section, we’ll be installing some of Rocket.Chat’s dependencies such as MongoDB and NodeJS.

Let’s start with getting MongoDB up and running. First, we need to add a keyserver so we can access the packages.

  1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Then we need to set the repo to use.

  1. echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

Now, update the package lists.

  1. sudo apt-get update

Now that that’s done, we can go ahead and install npm, mongodb-org, curl and graphicsmagick, which are all dependencies of Rocket.Chat:

  1. sudo apt-get install npm mongodb-org curl graphicsmagick

We need to install a package using NPM to allow us to change the node version:

  1. sudo npm install -g n

Use that package to change the node version to 0.10.40.

  1. sudo n 0.10.40

Next, we’ll install Rocket.Chat itself and do a little bit of configuration.

Step 2 — Installing Rocket.Chat

To start off, download the latest stable version of Rocket.Chat using curl.

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

Expand the archive we just downloaded using the tar command.

  1. tar zxvf rocket.chat.tgz

This expands the entire archive into a directory named bundle. Let’s move the contents of the bundle directory into something easier to remember.

  1. mv bundle Rocket.Chat

Change into the directory where we’ll install Rocket.Chat using NPM.

  1. cd Rocket.Chat/programs/server

Install Rocket.Chat.

  1. npm install

Move back into the parent Rocket.Chat directory.

  1. cd ../..

We need to set up some environmental variables to help Rocket.Chat keep track of things like URLs, ports, and more.

First, set the ROOT_URL variable to your domain name. This must be in the form of a URL.

  1. export ROOT_URL=https://example.com/

Set MongoDB’s URL under the MONGO_URL variable.

  1. export MONGO_URL=mongodb://localhost:27017/rocketchat

Set the PORT variable to 3000.

  1. export PORT=3000

Now you can run Rocket.Chat using the following command:

  1. node main.js

If there aren’t any errors, it works! For now, though, stop Rocket.Chat using CTRL+C. Now that Rocket.Chat is installed, we need to set up Nginx to proxy all of its traffic using a reverse proxy, making accessing Rocket.Chat easier and encrypting all of your communications with your SSL certificate.

Step 3 — Setting up a Reverse Proxy with Nginx

To start off, install Nginx.

  1. sudo apt-get install -y nginx

Move your certificate’s private key to /etc/nginx/certificate.key.

  1. sudo cp /path/to/your/key /etc/nginx/certificate.key

For example, if you created a Let’s Encrypt certificate, you would use sudo cp /etc/letsencrypt/live/your_domain_name/privkey.pem /etc/nginx/certificate.key.

Modify the key’s permissions so unauthorized thieves can’t gain access.

  1. sudo chmod 400 /etc/nginx/certificate.key

Copy the certificate itself to /etc/nginx/certificate.crt.

  1. sudo cp /path/to/your/cert /etc/nginx/certificate.crt

If you created a Let’s Encrypt certificate, the command would be similar to sudo cp /etc/letsencrypt/live/your_domain_name/cert.pem /etc/nginx/certificate.crt.

We’re going to be creating an entirely new configuration for Rocket.Chat, so you can delete the default to make it a little easier.

  1. sudo rm /etc/nginx/sites-enabled/default

If you need that file back for any reason in the future, it is still available at /etc/nginx/sites-available/default

Create a new /etc/nginx/sites-enabled/default with nano or your favorite text editor.

  1. sudo nano /etc/nginx/sites-enabled/default

First, we’ll add an upstream block:

/etc/nginx/sites-enabled/default
# Upstreams
upstream backend {
    server 127.0.0.1:3000;
}

Underneath that, let’s create a server block. The first part tells Nginx which port to listen for connections on, in this case :443. It also let’s it know what our hostname is. Don’t forget to replace example.com with your domain name.

/etc/nginx/sites-enabled/default
server {
    listen 443;
    server_name example.com;

Under that, we tell Nginx where to store Rocket.Chat’s access logs, and point it to the SSL certificate and key we placed in /etc/nginx/certificate.key and /etc/nginx/certificate.crt respectively.

/etc/nginx/sites-enabled/default
    error_log /var/log/nginx/rocketchat.access.log;

    ssl on;
    ssl_certificate /etc/nginx/certificate.crt;
    ssl_certificate_key /etc/nginx/certificate.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE

And now we finish the configuration off with a location block:

    location / {
        proxy_pass http://example.com:3000/;
        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;
    }
}

Here’s the full file for reference:

/etc/nginx/sites-enabled/default
server {
    listen 443;
    server_name example.com;
    error_log /var/log/nginx/rocketchat.access.log;

    ssl on;
    ssl_certificate /etc/nginx/certificate.crt;
    ssl_certificate_key /etc/nginx/certificate.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE

    location / {
        proxy_pass http://example.com:3000/;
        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;
    }
}

Save and exit the file. Finally, restart Nginx to finish the job.

  1. sudo service nginx restart

Check if Nginx is running.

  1. sudo service nginx status

If you see the following message, Nginx is up and running:

 * nginx is running

If you see an error message, check the logs at /var/log/nginx/rocketchat.access.log and /var/log/nginx/access.log or the error logs at /var/log/nginx/error.log. You can also run nginx -t to verify your Nginx configuration file, which is where most errors show up.

Make sure you’re still in the Rocket.Chat folder.

  1. cd ~/Rocket.Chat

Then run the following command to start Rocket.Chat back up again.

  1. node main.js

Rocket.Chat should now be live at https://example.com. You can verify this by visiting that address in your favorite browser.

In the next section, we’ll configure Rocket.Chat to automatically run at boot using a node module called forever-service.

Step 4 — Configuring Rocket.Chat as a Service

forever-service automatically generates init scripts for node apps such as Rocket.Chat. To start off, we need to install forever itself, which forever-service depends on.

  1. sudo npm install -g forever

Then, install forever-service.

  1. sudo npm install -g forever-service

Create a service using forever-service:

  1. sudo forever-service install -s main.js -e "ROOT_URL=https://example.com/ MONGO_URL=mongodb://localhost:27017/rocketchat PORT=3000" rocketchat
  • The -s flag followed by main.js tells forever-service our script is named main.js, not app.js, which is default.
  • The -e flag followed by "ROOT_URL=https://example.com/ MONGO_URL=mongodb://localhost:27017/rocketchat PORT=3000" passes our environmental variables to forever-service.
  • Finally, rocketchat tells forever-service what to name the service.

For more detailed information on forever-service’s syntax, run forever-service --help.

Now we can start Rocket.Chat. This will initialize the rocketchat service created by forever-service.

  1. sudo start rocketchat

Rocket.Chat should now be live at the URL you set in Step 2. Make sure you’re using HTTPS here.

Rocket.Chat should be is ready to go. In the next section, we’ll add our first admin user to Rocket.Chat and take a tour around the interface.

Step 5 — Configuring and Using Rocket.Chat

Visit the URL we set Rocket.Chat up on earlier. You should see something like this:

Rocket.Chat's login page

Click on Register a new account, then enter the user information for your first admin.

Rocket.Chat registration

Click Submit, and then choose a username for your new user:

Set a username for your new user

After clicking Use this username, you will be taken to the homepage:

Rocket.Chat's homepage

That’s all! You’ll see on the right, a #general channel has already been created for you. If you click on it, you’ll be taken to the chatroom. Feel free to play around a bit.

The default #general chatroom

Now let’s take a tour of the interface. First, let’s go ahead and make a new channel by clicking the tiny plus button next to Channels:

Create a new channel

Name it anything you’d like:

enter image description here

Now click Save, and you’ll be brought to your new channel.

To access the Administration interface, click the tiny arrow next to your username. It will pull down a menu:

Using this menu, you can set your status, and access things like the Administration menu.

Click on Administration. It will bring up a second menu:

This is the Administration menu.

Using this menu, we can configure and manage every aspect of our Rocket.Chat installation. In the Users section, we can manage the permissions of individual users, and even invite new ones. We can also add more features to our installation using the Integrations view.

Conclusion

Congratulations! You now have your very own chat solution for you and your team: Rocket.Chat, running on an Ubuntu 14.04 server. It is set to launch automatically at boot using forever-service and is fully equipped with SSL using an Nginx reverse proxy. You may now want to add more members, create more channels, or maybe check out the Integrations section of the Administration menu. Have fun!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Kellan

author


Default avatar

staff technical writer

hi! i write do.co/docs now, but i used to be the senior tech editor publishing tutorials here in the community.


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hi,

I am the Founder and CEO of Rocket.Chat

I’d like to have our app added to your DigitalOcean’s One-Click Applications, what should we do?

Cheers,

Gabriel Engel

Can you please update this tutorial to use NodeJS 4.5 now? Rocket.Chat has upgraded to use Meteor 1.4 now, and it won’t work with the older versions of NodeJS.

Now let’s use that package to change the node version to 4.5.0:

sudo n 4.5.0

how to update my rocket chat deployment ??

Thanks for the great tutorial.

I think I made a small mistake and I no longer can access the webUI. I am getting

ERR_TOO_MANY_REDIRECTS

I think the mistake I made was to enable SSL or Force SSL in the administration section. Is there a way to fix this?

This comment has been deleted

    it should be curl -L https://download.rocket.chat/stable -o rocket.chat.tgz

    Hi i’m setting the MONGOURL in the forever service to read the data from secondary mongo server export MONGO_URL=mongodb://10.xx.xx.xxx:27017,10.xx.xx.xxx:27017/Chat?replicaSet=rs1&readPreference=nearest not working for me…help needed

    I followed all instruction, very easy by the way, and all works great. However now for a couple of days I have this error: Warning! The 161.50 MB filesystem mounted at /snap/rocketchat-server/653 has no free disk space! Warning! The 79.50 MB filesystem mounted at /snap/core/1689 has no free disk space! Any idea why I am getting those error and how I could increase the disk space for those app. For information the server disk is only used at 30% of capacity so there is plenty of free space.

    For anyone still having trouble getting RocketChat going, or who doesn’t want to maintain their own hosting stack just to power their team chat, check out http://rocketchatlauncher.com - a brand new SaaS offering I just launched for RocketChat which requires no code or server setup (which itself is running out of Digital Ocean’s Toronto data centre!) ;)

    After running node main.js i am getting the below error Updating process.env.MAIL_URL ufs: permissions are not defined for store “fileSystem” ufs: store created at ufs: permissions are not defined for store “fileSystem”.

    Can some one help me how to get out of this issue

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel