Learn How To Deploy a Let’s Chat Server on CentOS 7
Table of Contents
- Prerequisites
- Step 1: Update the system
- Step 2: Install NodeJS
- Step 3: Install MongoDB
- Step 4: Install Let’s Chat
- Step 5 (optional): Create the settings.yml file
- Step 6: Install Forever
- Step 7: Install Nginx as a reverse proxy
- Step 8: Web access
Let’s Chat is an open source chat application is designed to provide self-hosted messaging service for small teams.
Let’s Chat is based on NodeJS and MongoDB. In this article, we’ll take a look at how to deploy Let’s Chat on a CentOS 7 sever.
Prerequisites
- A CentOS 7 server instance with at least 2G RAM. 4G RAM recommended.
- A sudo user.
Step 1: Update the system
When logging into your system for the first time, it’s necessary to perform a system-wide update as follows:
sudo yum install epel-release -y
sudo yum clean all && sudo yum update -y && sudo shutdown -r now
After the reboot, log in back as the same sudo user.
Step 2: Install NodeJS
Install the latest NodeJS 6.x as follows, which is 6.9.5
at the time of writing:
cd
curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
sudo yum install -y nodejs
Step 3: Install MongoDB
Install the latest MongoDB as follows, which is 3.4
at the time this article was written.
3.1 Create the MongoDB 3.4 YUM repo as follows:
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 the latest stable release of MongoDB Server, which is 3.4.1
at the time this article was written:
sudo yum install -y mongodb-org
sudo systemctl start mongod.service
sudo systemctl enable mongod.service
Step 4: Install Let’s Chat
sudo yum install git -y
cd /opt
sudo git clone https://github.com/sdelements/lets-chat.git
cd lets-chat
sudo npm install
Note: It’s normal to see several npm WARN ...
messages during the installation. Just ignore them.
Step 5 (optional): Create the settings.yml
file
If you want to customize Let’s Chat, you can create a file named /opt/lets-chat/settings.yml
and then put your custom settings in it:
sudo cp settings.yml.sample settings.yml
For the purpose of this tutorial, we will use the default settings from the sample settings file.
Step 6: Install Forever
You can start Let’s Chat from the /opt/lets-chat
directory:
cd /opt/lets-chat
npm start
The output should resemble:
> lets-chat@0.4.8 start /opt/lets-chat
> node app.js
██╗ ███████╗████████╗███████╗ ██████╗██╗ ██╗ █████╗ ████████╗
██║ ██╔════╝╚══██╔══╝██╔════╝ ██╔════╝██║ ██║██╔══██╗╚══██╔══╝
██║ █████╗ ██║ ███████╗ ██║ ███████║███████║ ██║
██║ ██╔══╝ ██║ ╚════██║ ██║ ██╔══██║██╔══██║ ██║
███████╗███████╗ ██║ ███████║ ╚██████╗██║ ██║██║ ██║ ██║
╚══════╝╚══════╝ ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
Release 0.4.8
In order to keep the Let’s Chat application running, let’s press Ctrl-C
first to exit and then install an app named forever
which can ensure that will happen:
sudo npm install forever -g
Use the forever
application to start Let’s Chat:
cd /opt/lets-chat
forever start app.js
After Let’s Chat gets up and running, you can access it locally via:
http://localhost:5000
You can test your installation with the below command:
curl -I http://localhost:5000
The output should be similar to:
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: Install Nginx as a reverse proxy
In order to enable external web access, you need to setup a reverse proxy, Nginx, for example, to redirect traffic.
7.1 Install Nginx:
sudo yum install nginx -y
7.2 Modify Nginx’s settings:
sudo vi /etc/nginx/nginx.conf
Find the location / {}
segment within the http {}
segment:
http {
location / {
}
}
Insert the below lines into the location / {}
segment:
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
proxy_pass http://127.0.0.1:5000;
The final result should be:
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 quit:
:wq!
7.3 Start the Nginx service:
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
7.4 Modify firewall rules in order to allow web access:
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
Step 8: Web access
Point your web browser to http://203.0.113.1
to access Let’s Chat, and then click the I need an account
link to register a username for logging in.
That’s it. Thanks for reading.
Need help?
Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!