• Get In Touch
March 3, 2017

How to Install Let’s Chat on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Let’s Chat is a free, open source chat application. It is very lightweight and written in Node.js. It uses MongoDB to store the application data. Let’s Chat has many features such as LDAP Authentication, XMPP multi user chat, Desktop notifications, Private chat rooms, File uploads etc. The application is available in more than 18 languages.

In this tutorial, we will learn to install Let’s Chat on CentOS 7.

Requirements

Let’s Chat can be installed on a server with a small amount of memory. The requirement of RAM increases as the number of users increases. You will also need a minimal installation of CentOS 7 with root access on it. If you are logged in as a non-root user, you can run sudo -i to switch to root user.

Installing Let’s Chat

Before installing any package it is recommended that you update the packages and repository using the following command.

yum -y update

Once your system is updated, you will need to install Node.js. To install the latest version of Node.js from the nodesource repository, run the following command.

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

Let’s Chat uses MongoDB to store its data. MongoDB community version is not found on the YUM 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 Python 2.7. Download the Python Source using following command.

cd /tmp
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz

To compile and install the code, you will need to install GCC. Run the following command to install GCC.

yum -y install gcc

Now extract the archive using the following command.

tar xzf Python-2.7.13.tgz

Compile and install the software using following commands.

cd Python-2.7.13
./configure
make altinstall

It will take few minutes to install the software. Once Python is installed, you can run the following command to check if it is successfully installed.

python2.7 -V

You can also create a soft link to the file using the following command, so that you can run python command instead of python2.7.

ln -s /usr/local/bin/python2.7 /usr/local/bin/python

You will also need to install Git to clone the Let’s Chat files. Run the following command for same.

yum -y install git

Once the dependencies are installed, you can now proceed to install Let’s Chat. Clone the project to your local computer using the following command.

cd /var
git clone https://github.com/sdelements/lets-chat.git
cd lets-chat

Run the following command to install the application.

npm install

Once you have installed the application, you can now copy the configuration file using the following command.

cp settings.yml.sample settings.yml

You can also configure the settings by editing settings.yml file. You can now start the server using the following command.

npm start
Once you run the above command, you will see following output.

[root@liptan-pc lets-chat]# npm start

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


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

Release 0.4.8

Your application is now running on http://YourServerIP:5000. To stop the application you can press the combination of Ctrl + C buttons.

Now we will need to create a Systemd service so that application can be started and stopped as service.

To create the systemd service file, run the following command.

nano /etc/systemd/system/letschat.service

Copy and paste the following contents in the file.

[Unit]
Description=Let's Chat Server
Wants=mongodb.service
After=network.target mongodb.service

[Service]
Type=simple
WorkingDirectory=/var/lets-chat
ExecStart=/usr/bin/npm start
User=root
Group=root
Restart=always
RestartSec=9

[Install]
WantedBy=multi-user.target

Save the file and exit from the editor.

You can now start the application using the following command.

systemctl start letschat

To enable the application to automatically start at boot time run the following command.

systemctl enable letschat

You can check the status of the service using the following command.

systemctl status letschat

Instead of accessing the application on port 5000, you should create a reverse proxy for your application with either Apache or nginx. In this tutorial, we are going to use Apache as the reverse proxy for your application. We will also secure the application using Let’s Encrypt free SSL. If you want to use more secure and trusted SSL certificates, you can purchase SSL certificates from HostPresto also.

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:5000/sockjs/$1/websocket
  ProxyPass / http://localhost:5000/
  ProxyPassReverse / http://localhost:5000/

  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

Now you can start the Let’s Chat service if not started already using the following command.

systemctl start letschat

Now you will need to disable your SELinux because reverse proxy does not work with SELinux policies. To temporary disable SELinux without restarting the server, run the following command.

setenforce 0

To completely disable the SELinux you will need to edit the /etc/selinux/config file.

nano /etc/selinux/config

If you don’t have nano installed, you can install it using yum -y install nano Find the following line:

SELINUX=enforcing

Change it to:

SELINUX=disabled

Now you will need to reboot your server so that the new configuration can take effect. Once the server is up again you can access your application at the following URL.

https://yourdomain.com

You will see following login screen.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/55715240.png” alt=”” />

Click on I need an account link and fill out all the required information and click Register button.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/1479005227.png” alt=”” />

Once the account is created, you can login using your newly created account. Once logged in you will see the following screen.

HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/1919080616.png” alt=”” />

Conclusion

In this tutorial, we have learned how to install Let’s 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.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]