Deploying Let’s Chat on CentOS 7: A Step-by-Step Guide

Let’s Chat is a free and open source chat platform tailored for self-hosted messaging needs of small teams.

This application is built using NodeJS and MongoDB. This tutorial explains how to install and deploy Let’s Chat on a CentOS 7 server environment.

Requirements

  • A CentOS 7 server with a minimum of 2GB RAM (4GB is recommended)
  • Access to a user account with sudo privileges

Step 1: Perform System Updates

Once logged into your server, start by updating the entire system:

sudo yum install epel-release -y
sudo yum clean all && sudo yum update -y && sudo shutdown -r now

After the reboot, reconnect using the same sudo-enabled user account.

Step 2: Install NodeJS

Install NodeJS version 6.x (version 6.9.5 was current at the time of this guide):

cd
curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
sudo yum install -y nodejs

Step 3: Install MongoDB

Install MongoDB version 3.4 using the steps below.

3.1 Configure MongoDB YUM Repository

Create the repository file for MongoDB 3.4:

cat <<EOF | sudo tee -a /etc/yum.repos.d/mongodb-org-3.4.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
EOF

3.2 Install and Start MongoDB

Install and activate MongoDB server version 3.4.1:

sudo yum install -y mongodb-org
sudo systemctl start mongod.service
sudo systemctl enable mongod.service

Step 4: Install Let’s Chat

Proceed to download and install Let’s Chat from its GitHub repository:

sudo yum install git -y
cd /opt
sudo git clone https://github.com/sdelements/lets-chat.git
cd lets-chat
sudo npm install

Note: During the npm installation, you might encounter multiple warnings (npm WARN …). These can be safely disregarded.

Step 5 (Optional): Configure Custom Settings

If you wish to personalize the application, you can duplicate and edit the sample settings file:

sudo cp settings.yml.sample settings.yml

For this tutorial, the sample file is used without further modification.

Step 6: Run Let’s Chat with Forever

To start Let’s Chat manually, go to the installation directory and run the application:

cd /opt/lets-chat
npm start

You should see output similar to this:

> lets-chat@0.4.8 start /opt/lets-chat
> node app.js

██╗     ███████╗████████╗███████╗     ██████╗██╗  ██╗ █████╗ ████████╗
██║     ██╔════╝╚══██╔══╝██╔════╝    ██╔════╝██║  ██║██╔══██╗╚══██╔══╝
██║     █████╗     ██║   ███████╗    ██║     ███████║███████║   ██║   
██║     ██╔══╝     ██║   ╚════██║    ██║     ██╔══██║██╔══██║   ██║   
███████╗███████╗   ██║   ███████║    ╚██████╗██║  ██║██║  ██║   ██║   
╚══════╝╚══════╝   ╚═╝   ╚══════╝     ╚═════╝╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝

Release 0.4.8

To keep Let’s Chat running after you close the terminal, press Ctrl-C to stop it for now, then install the forever package globally:

sudo npm install forever -g

Now launch the app using Forever:

cd /opt/lets-chat
forever start app.js

Once running, Let’s Chat will be available locally at:

http://localhost:5000

You can verify that it’s working by using:

curl -I http://localhost:5000

The expected output should look like:

HTTP/1.1 302 Found
X-Frame-Options: SAMEORIGIN
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy:
X-Content-Security-Policy:
X-WebKit-CSP:
X-UA-Compatible: IE=Edge,chrome=1
Location: /login
Vary: Accept, Accept-Encoding
Content-Type: text/plain; charset=utf-8
Content-Length: 28
set-cookie: connect.sid=s%3A0YTFL6Un5G7iMc3zt8i-vlIh2YDQqTZ3.1dVZFG3VWmwd%2FXXXJiuyWSQ4k432MVvxm7xrgJGIej4; Path=/; HttpOnly
Date: Wed, 01 Feb 2017 11:30:03 GMT
Connection: keep-alive

Step 7: Set Up Nginx as a Reverse Proxy

To make Let’s Chat accessible from the internet, configure a reverse proxy using Nginx.

7.1 Install Nginx

7.2 Adjust Nginx Configuration

Edit the Nginx configuration file:

sudo vi /etc/nginx/nginx.conf

Inside the http {} block, locate the location / {} section and replace it with the following:

http {

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_cache_bypass $http_upgrade;
    }

}

Save and close the file with:

:wq!

7.3 Launch Nginx

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

7.4 Update Firewall Rules

Allow web traffic through the firewall with these commands:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

Step 8: Access via Web Browser

Open your browser and visit http://203.0.113.1 to load the Let’s Chat interface. Use the “I need an account” link to register and create a new user account.

Conclusion

By following this step-by-step guide, you’ve successfully installed and configured Let’s Chat on a CentOS 7 server. With NodeJS, MongoDB, and Forever ensuring stability, and Nginx providing a reliable reverse proxy, your self-hosted chat environment is now ready for small team collaboration. You can further enhance security and functionality by customizing the settings.yml file or integrating SSL for encrypted communication. Let’s Chat offers a solid, open-source alternative for private team messaging.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in:

Moderne Hosting Services mit Cloud Server, Managed Server und skalierbarem Cloud Hosting für professionelle IT-Infrastrukturen

Secure HTTPS Setup on Arch Linux with Apache or Nginx

Security, Tutorial

Linux file permissions with this comprehensive guide. Understand how to utilize chmod and chown commands to assign appropriate access rights, and gain insights into special permission bits like SUID, SGID, and the sticky bit to enhance your system’s security framework.