NodeBB is free and open source community forum software. It is written in Node.js and uses Redis or MongoDB to store the data. NodeBB has a modern look and it is completely responsive. It comes with all the features of community forums along with social media integration. It uses web sockets for instant interaction and real-time notifications. The features of the application can be further increased by using themes and plugins.
In this tutorial, we will be installing NodeBB forum on CentOS 7.
Requirements
NodeBB does not require any special hardware requirements. It can be installed on servers with a small amount of RAM. But the requirement of RAM increases as the user increases. All the required dependencies will be installed throughout the tutorial. You will 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 NodeBB
Before installing any package it is recommended that you update the packages and repository using the following command.
yum -y update
Now you will need to install EPEL repository as we will need to install few packages which are not available in the default yum repository. Run the following command to install EPEL repository.
yum -y install epel-release
yum -y update
Now you will need to install the Development Tools
which will install the required tools for compile and build the source code. Run the following command for same.
yum -y groupinstall "Development Tools"
Now install the software stack required for NodeBB using following command.
yum -y install git redis ImageMagick
The above command will install git, redis, and ImageMagick. Now install the latest version of Node.js from the nodesource repository using the following commands.
curl --silent --location https://rpm.nodesource.com/setup_7.x | bash -
yum -y install nodejs
Once Node.js is installed, you can start Redis and enable it to start at boot time using following commands.
systemctl start redis
systemctl enable redis
Now you will need to clone the setup files from NodeBB repository to your server. In this tutorial, we will use /var/nodebb
directory to install NodeBB. You can also choose a different path. To create a new directory to install NodeBB, run the following command.
mkdir /var/nodebb
cd /var/nodebb
Now clone the NodeBB files into the current directory using the following commands.
git clone https://github.com/NodeBB/NodeBB.git .
Once the software is cloned, you can install all the dependencies required by NodeBB using following command.
npm install
If you get any error during the execution of the above command, it is likely that node-gyp
is not installed, run the following command to install node-gyp
and fix the error.
npm -g install node-gyp
npm cache clean
rm -rf node_modules
npm install
The above command could take some time to download and install the dependencies. Once done, run the following command to initialize the setup script and start the installer.
./nodebb setup
Now you will need to answer few questions asked by the installer. It will ask you about the URL for your NodeBB installation, just press enter to use the default value. Further, it will ask you about the NodeBB secret, just press to use the default value. Next, it will ask you which database to use, enter redis
and press enter.
The installer will now start to configure Redis. Press enter to use the default value for IP address, port, administrator password and database for Redis instance.
Finally, it will ask you to provide the information for the administrator. Provide a username, email, and password of the administrator.
The output of the script will look as shown below. Log messages are removed from the output.
[root@liptan-pc nodebb]# ./nodebb setup
Welcome to NodeBB!
This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.
Press enter to accept the default setting (shown in brackets).
URL used to access this NodeBB (http://localhost:4567)
Please enter a NodeBB secret (afa37197-712f-474a-88ff-e722a041aa40)
Which database to use (mongo) redis
Host IP or address of your Redis instance (127.0.0.1)
Host port of your Redis instance (6379)
Password of your Redis database
Which database to use (0..n) (0)
Configuration Saved OK
Populating database with default configs, if not already set...
Administrator username liptan
Administrator email address me@liptanbiswas.com
Password
Confirm Password
Creating welcome post!
Enabling default plugins
NodeBB Setup Completed. Run './nodebb start' to manually start your NodeBB server.
If you provide any incorrect values during the setup, you can restart the setup by executing the above command again, but you will need to remove the configuration file using rm /var/nodebb/config.json
. You can also edit the configuration file using a text editor.
To immediately start the forum, run the following command.
./nodebb start
Although it is best practice to run the NodeBB server on localhost listening on port 4567, and create a reverse proxy with Apache or nginx to serve the site on the internet. Also instead of running NodeBB server using commands, it is recommended to create a systemd service so that the application can be started automatically on crashes and boot time. To create a systemd service for NodeBB you will need to create a new service file using the following command.
nano /etc/systemd/system/nodebb.service
If you do not have nano
installed, you can run yum -y install nano
. Now paste the following text into the nano editor.
[Unit]
Description=NodeBB service
After=syslog.target
After=network.target
[Service]
User=root
Type=simple
ExecStart=/usr/bin/node /var/nodebb/app.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodebb
[Install]
WantedBy=multi-user.target
Now you can start NodeBB server and configure it to automatically start at boot time using following commands.
systemctl start nodebb
systemctl enable nodebb
To check if the NodeBB service is started correctly, you can run the following command to check the status of the NodeBB service.
systemctl status nodebb
Configuring nginx as Reverse Proxy with Let’s Encrypt SSL
Instead of using the application on Port 4567, you can use nginx to run on port 80 or 443 in the case of using SSL. This way the main application will run on port 4567, and nginx will work as a reverse proxy. Install nginx web server with the following command.
yum -y install nginx
Now we will need to generate SSL certificates from Let’s Encrypt client. If you can want to use commercial SSL certificates instead, you can purchase SSL certificates from HostPresto.
To install Let’s Encrypt client also called Certbot run the following command.
yum -y install certbot
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. Make sure that you do not have nginx running at this moment.
certbot certonly --standalone -d yourdomain.com -d www.yourdomain.com
This command will run Let’s Encrypt client to obtain the certificates only but will not install it. --standalone
tells the client to use the standalone web server for authentication of domain authority. -d yourdomain.com
tells the domain name for which the certificates needs to be obtained. Provide your email address and accept the terms and conditions. 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 the SSL certificates are now generated, we can proceed further to configure nginx configuration file. Now create a new server block for nginx configuration file using the following command.
nano /etc/nginx/conf.d/ssl-yourdomain.com.conf
Replace yourdomain.com
with your actual domain. Now copy and paste the following lines into the file.
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 http2 ssl;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
location / {
proxy_set_header Host $host;
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_pass http://localhost:4567;
proxy_read_timeout 90;
proxy_redirect http://localhost:4567 https://yourdomain.com;
}
}
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. Now start nginx web server and enable it to automatically start at boot time using the following commands.
systemctl start nginx
systemctl enable nginx
Now you will need to disable your SELinux because NodeBB 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/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. Now you can start the NodeBB service if not started already using the following command.
systemctl start nodebb
You can now browse the following URL in your favorite browser.
https://YourDomain.com
You will see the following screen.
HP_NO_IMG/data/uploads/users/e840080c-7322-4497-85c0-150182bd4c02/822861953.png” alt=”” />
Conclusion
In this tutorial, we have learned how to install NodeBB forum on CentOS 7. You can now successfully deploy the application to quickly setup and discussion forum for your community or organization.