How to Install NodeBB Forum on CentOS 7

NodeBB is a Node.js based forum software built for the modern web. It's built on either a MongoDB or Redis database. It utilizes web sockets for instant interactions and real-time notifications. NodeBB has many modern features out of the box such as social network integration and streaming discussions. Additional functionality is enabled through the use of third-party plugins. NodeBB is an open source project which can be found on GithubIn this guide, we will walk you through the step-by-step NodeBB installation process on the CentOS 7 operating system.

Requirements

NodeBB requires the following software to be installed:

  • Node.js version 6 or greater
  • MongoDB version 2.6 or greater or Redis version 2.8.9 or greater
  • Nginx version 1.3.13 or greater
  • Git

Prerequisites

  • A server running CentOS 7 x86_64 (64-bit) system with at least 1GB or RAM
  • Domain name with A/AAAA records set up
  • A non-root user with sudo privileges.

Initial steps

Check the CentOS version:

cat /etc/centos-release
# CentOS Linux release 7.5.1804 (Core)

Set up the timezone:

timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'

Update your operating system packages (software):

sudo yum update -y

Install necessary packages to finish this tutorial:

sudo yum install -y curl wget vim bash-completion git socat epel-release

For simplicity's sake, disable SELinux and Firewall:

sudo setenforce 0; sudo systemctl stop firewalld.service; sudo systemctl disable firewalld.service

Step 1: Install Node.js and npm

NodeBB is built on Node.js. We are going to install recommended version for NodeBB which is version 8 at the time of this writing. On Linux you have a few Node.js installation options: Linux Binaries (x86/x64), Source Code or via Package Managers. We will use Package Managment option which makes installing and updating Node.js a breeze.

Download and install the latest Long-Term Support (LTS) release of Node.js from the Nodesource repository:

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

To compile and install native addons from npm you may also need to install build tools:

sudo yum install -y gcc-c++ make
# or
# sudo yum groupinstall -y 'Development Tools'

NOTE: npm is distributed with Node.js - which means that when you download Node.js, you automatically get npm installed on your system.

Check the Node.js and npm versions:

node -v && npm -v
# v8.12.0
# 6.4.1

Npm is a separate project from Node.js, and tends to update more frequently. As a result, even if you’ve just downloaded Node.js (and therefore npm), you’ll probably need to update your npm. Luckily, npm knows how to update itself! To update your npm, type this into your terminal:

sudo npm install -g npm@latest

This command will update npm to the latest stable version.

Step 2: Install and configure MongoDB

NodeBB needs database to store its data, and it supports MongoDB and Redis. In this tutorial, we chose MongoDB as data store engine. So, in the next few steps, we will download and install MongoDB database from the official MongoDB rpm repository:

Create a /etc/yum.repos.d/mongodb-org-4.0.repo file, so that you can install MongoDB directly using yum:

sudo vim /etc/yum.repos.d/mongodb-org-4.0.repo

Populate the file with the following content:

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

To install the latest stable version of MongoDB package, issue the following command:

sudo yum install -y mongodb-org

Check the MongoDB version:

mongo --version | head -n 1 && mongod --version | head -n 1
# MongoDB shell version v4.0.2
# db version v4.0.2

Start and enable (set it to start on rebootMongoDB service:

sudo systemctl start mongod.service
sudo systemctl enable mongod.service

Check the MongoDB Database Server status by running:

sudo systemctl status mongod.service
# active (running)

Next, create MongoDB database and user for NodeBB.

Connect to MongoDB server first.

mongo

Switch to the built-in admin database.

> use admin

Create an administrative user.

> db.createUser( { user: "admin", pwd: "<Enter a secure password>", roles: [ { role: "readWriteAnyDatabase", db: "admin" }, { role: "userAdminAnyDatabase", db: "admin" } ] } )

NOTE: Replace the placeholder <Enter a secure password> with your own selected password.

Add a new database called nodebb.

> use nodebb

The database will be created and context switched to nodebb. Next create the nodebb user with the appropriate privileges.

> db.createUser( { user: "nodebb", pwd: "<Enter a secure password>", roles: [ { role: "readWrite", db: "nodebb" }, { role: "clusterMonitor", db: "admin" } ] } )

NOTE: Again, replace the placeholder <Enter a secure password> with your own selected password.

Exit the Mongo shell.

> quit()

Restart MongoDB and verify that the administrative user created earlier can connect.

sudo systemctl restart mongod.service
mongo -u admin -p your_password --authenticationDatabase=admin

If all went well, your MongoDB should be installed and prepared for NodeBB. In the next step, we will deal with web server installation and configuration.

Step 3: Install Acme.sh client and obtain a Let's Encrypt certificate (optional)

Securing your NodeBB forum with HTTPS is not necessary, but it is a good practice to secure your site traffic. In order to obtain SSL certificate from Let's Encrypt we will use Acme.sh client. Acme.sh is a pure unix shell software for obtaining SSL certificates from Let's Encrypt with zero dependencies. 

Download and install Acme.sh:

sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail [email protected]
cd ~

Check Acme.sh version:

/etc/letsencrypt/acme.sh --version
# v2.8.0

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d forum.example.com --ocsp-must-staple --keylength 2048
# ECDSA
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d forum.example.com --ocsp-must-staple --keylength ec-256

After running the above commands, your certificates and keys will be in:

  • For RSA: /etc/letsencrypt/forum.example.com directory.
  • For ECC/ECDSA: /etc/letsencrypt/forum.example.com_ecc directory.

Step 4: Install and configure Nginx

NodeBB can work fine with many web servers. In this tutorial, we selected Nginx.

Download and import Nginx repository PGP key first:

wget https://nginx.org/keys/nginx_signing.key
sudo rpm --import nginx_signing.key

After importing the key, you can safely remove it from the disk:

rm nginx_signing.key

Create a /etc/yum.repos.d/nginx_mainline.repo file, so that you can install Nginx directly using yum:

sudo vim /etc/yum.repos.d/nginx_mainline.repo

Populate the file with the following content:

[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=1
enabled=1

Finally, to install the latest mainline version of Nginx package, issue the following command:

sudo yum install -y nginx

After the installation, you can verify Nginx version by running:

nginx -v
# 1.15.3

Start and enable (set it to start on reboot) Nginx service:

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

Check the Nginx web server status by running:

sudo systemctl status nginx.service
# active (running)

NodeBB by default runs on port 4567. To avoid typing http://example.com:4567, we will configure Nginx as a reverse proxy for the NodeBB application. Every request on port 80 or 443 (if SSL is used) will be forwarded to port 4567.

Run sudo vim /etc/nginx/conf.d/nodebb.conf and configure Nginx as an HTTPS reverse proxy.

server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
listen [::]:80;
listen 80;

server_name forum.example.com;

client_max_body_size 50M;

# RSA
ssl_certificate /etc/letsencrypt/forum.example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/forum.example.com/forum.example.com.key;
# ECDSA
ssl_certificate /etc/letsencrypt/forum.example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/forum.example.com_ecc/forum.example.com.key;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4567;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

}

Check the Nginx configuration:

sudo nginx -t

Finally, for changes to take effect, we need to reload Nginx:

sudo systemctl reload nginx.service

Step 5: Install and setup NodeBB

Create a document root directory where NodeBB should reside in:

sudo mkdir -p /var/www/nodebb

Navigate to the document root directory:

cd /var/www/nodebb

Change ownership of the /var/www/nodebb directory to your_user.

sudo chown -R [your_user]:[your_user] /var/www/nodebb

NOTE: Replace your_user in the above command with your non-root user that you should have created as a prerequisite for this tutorial.

Clone the latest NodeBB repository into document root folder:

git clone -b v1.10.x https://github.com/NodeBB/NodeBB.git .

Initiate the setup script by running the app with the setup flag:

./nodebb setup

After NodeBB setup is completed, run ./nodebb start to manually start your NodeBB server:

./nodebb start

After running this command, you should be able to access your brand new forum in your web browser:

NodeBB in Browser

Step 6: Run NodeBB as a System Service

When started via ./nodebb start, NodeBB will not automatically start up again when the system reboots. To avoid that, we will need to setup NodeBB as a system service.

If running, stop NodeBB:

./nodebb stop

Create a new nodebb user:

sudo useradd nodebb

Change the ownership of the /var/www/nodebb directory to nodebb user:

sudo chown -R nodebb:nodebb /var/www/nodebb

Create nodebb.service systemd unit config file. This unit file will handle startup of NodeBB deamon. Run sudo vim /etc/systemd/system/nodebb.service and add the below content:

[Unit]
Description=NodeBB
Documentation=https://docs.nodebb.org
After=system.slice multi-user.target mongod.service

[Service]
Type=forking
User=nodebb

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodebb

Environment=NODE_ENV=production
WorkingDirectory=/var/www/nodebb
PIDFile=/var/www/nodebb/pidfile
ExecStart=/usr/bin/env node loader.js
Restart=always

[Install]
WantedBy=multi-user.target

NOTE: Set username and directory paths according to your chosen names.

Enable nodebb.service on reboot and immediately start nodebb.service:

sudo systemctl enable nodebb.service
sudo systemctl start nodebb.service

Check the nodebb.service status:

sudo systemctl status nodebb.service
sudo systemctl is-enabled nodebb.service

Congratulations! You have successfully installed and deployed NodeBB discussion platform on CentOS 7 server.

Links

Share this page:

0 Comment(s)