How to Install NodeBB on CentOS 7

Updated on March 9, 2017
How to Install NodeBB on CentOS 7 header image

NodeBB is a modern, open source, and NodeJS-based forum software.

With customers in mind, NodeBB offers community owners powerful features and ease of use to drive community engagement.

In this article, we will be installing NodeBB on CentOS 7.

Prerequisites

  • A newly deployed Vultr CentOS 7 x64 server instance at least 1 GB RAM.
  • Logging in as the root user.
  • The EPEL yum repository.

Step 1: Update the system

Log in to your server via SSH using the sudo user to install epel, update the system, and restart to apply the updates.

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

Step 2: Install dependencies for NodeBB

Next, we will install all the NodeBB required system dependancies:

yum -y groupinstall "Development Tools"
yum -y install git redis ImageMagick npm

Start redis and make it run at each and every system startup:

systemctl start redis.service
systemctl enable redis.service

Step 3: Install NodeJS using nvm

Use the following commands to install NodeJS v6.9.5—the latest LTS release of NodeJS at the time this article was written.

Note: The second command below will invoke nvm v0.33.0, the latest release of nvm at the time of writing this article. You can always check out the latest release of nvm here and then modify that command accordingly.

cd
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
source ~/.bash_profile
nvm list-remote
nvm install v6.9.5

Step 4: Install NodeBB

Install the latest release of NodeBB, NodeBB v1.4.3, as follows:

cd /opt
git clone -b v1.4.3 https://github.com/NodeBB/NodeBB nodebb
cd nodebb
npm install

After the installation, run the ./nodebb script with the setup flag in order to setup NodeBB:

./nodebb setup

Answer a few questions as follows in order to use the default settings with a redis database. When appropriate, press Enter to accept the default setting shown in brackets.

  • URL used to access this NodeBB (http://localhost:4567) <Enter>
  • Please enter a NodeBB secret (bb3244f1-3a7e-4ee2-bc77-5032fd4c8b00) <Enter>
  • Which database to use (mongo) redis
  • Host IP or address of your Redis instance (127.0.0.1) <Enter>
  • Host port of your Redis instance (6379) <Enter>
  • Password of your Redis database <Enter>
  • Which database to use (0..n) (0) <Enter>
  • Administrator username admin
  • Administrator email address admin@example.com
  • Password yourpassword
  • Confirm Password yourpassword

Having NodeBB successfully installed and configured, you can manually start/stop/restart NodeBB by running:

./nodebb start
./nodebb stop
./nodebb restart

Step 5: Keep NodeBB running using forever

Forever is a tool which can keep nodejs-based app running. In production, this is a useful feature.

First, you need to stop NodeBB:

./nodebb stop

Install forever globally:

npm install forever -g

Start NodeBB using forever:

cd /opt/nodebb
forever start app.js

You can confirm that NodeBB is running using a curl command:

curl -I http://localhost:4567

The output should resemble:

HTTP/1.1 200 OK
X-Powered-By: NodeBB
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: null
Content-Type: text/html; charset=utf-8
Content-Length: 19845
ETag: W/"4d85-cXlw1a5DyxHkfjSEd7Ru5Q"
set-cookie: express.sid=s%3AqoIQ1-JSyw1tvrrhyXiP7Sm5D-gDJ9HT.Aum4qMXBPiCgZ7Il%2BtrePafZJWEt2dIJlS%2BBTRZjWZs; Path=/; Expires=Sun, 26 Feb 2017 15:14:35 GMT; HttpOnly
Vary: Accept-Encoding
Date: Sun, 12 Feb 2017 15:14:36 GMT
Connection: keep-alive

Step 6: Setup an Nginx reverse proxy

Since NodeBB is running on localhost by default, you need to setup an Nginx reverse proxy in order to allow web access.

Install Nginx using YUM:

yum install nginx -y

Modify Nginx settings:

vi /etc/nginx/nginx.conf

Find the location / {} segment within the http {} segment:

http {

    location / {
    }

}

Insert the below lines into the location / {} segment:

    proxy_pass http://127.0.0.1:4567;
    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;

The final result should be:

http {

location / {
    proxy_pass http://127.0.0.1:4567;
    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!

Start and enable the Nginx service:

systemctl start nginx.service
systemctl enable nginx.service

Step 7: Modify firewall rules in order to allow visitors' access:

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

Step 8: Access NodeBB

Finally, point your web browser to http://203.0.113.1 to visit the newly created NodeBB website. You can log in using the admin credentials you setup earlier. Feel free to navigate and customize NodeBB after logging in as the administrator.