How to install NodeBB forum on Ubuntu 24.04

This article provides comprehensive guidance on installing NodeBB Forum with Nginx on Ubuntu 24.04. It emphasizes the enhanced web traffic handling and security benefits, the PostgreSQL database setup, Node.js installation, Git configuration, NodeBB as a systemd service, and the use of a reverse proxy for optimizing web traffic and accessibility.

This article explains installing NodeBB Forum with a reverse proxy on Ubuntu 24.04.

NodeBB, a modern, efficient, and extensible forum software built using Node.js, can be further optimized by including Nginx, a powerful web server and reverse proxy. This setup on Ubuntu enhances web traffic handling and boosts security through Nginx’s features like rate limiting and SSL termination.

Moreover, it significantly improves the performance and scalability of the NodeBB forum. Nginx’s dual role of serving static content efficiently and proxying dynamic requests to the NodeBB application server is a key aspect of this setup, aiding in load balancing and caching, thereby ensuring a superior user experience.

The steps below walk you through installing the NodeBB forum platform with Nginx or Apache reverse proxy on Ubuntu 24.04.

Install PostgreSQL

Before installing NodeBB, you must install a database server to store its content. A database server that works excellently with NodeBB is PostgreSQL.

Use the steps below to install it on Ubuntu.

First, add the PostgreSQL GPG key to Ubuntu. Run the command below to do that.

sudo apt install curl
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-key.gpg >/dev/null

Then, add the PostgreSQL APT repository to your sources list.

sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-key.gpg arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Next, update and refresh the repository list and install PostgreSQL.

sudo apt update
sudo apt install postgresql postgresql-contrib

More details on installing PostgreSQL can be found in the link below.

How to install PostgreSQL on Ubuntu

Configure PostgreSQL and create NodeBB database

Once PostgreSQL is installed, use the steps below to configure it and create a database for NodeBB.

First, log on to the PostgreSQL console by running the command below.

sudo -u postgres psql

Run the command below to change or create a password for the administrator account. Confirm the password when prompted.

\password postgres

Next, create a NodeBB database user account called ‘nodebbuser.’

CREATE ROLE nodebbuser WITH LOGIN ENCRYPTED PASSWORD 'type_strong_password_here';

Replace ‘type_strong_password_here‘ with your password.

Next, create a ‘nodebbdb‘ database for NodeBB and make the user above owner.

CREATE DATABASE nodebbdb OWNER nodebbuser;

Exit the database console.

\q

Install Node.js

The NodeBB forum is written using the Node.js framework. You’ll need a Node.js framework installed to run NodeBB.

Run the command below to install it.

curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install nodejs

Install Git

You will also need Git installed to use and configure NodeBB. Then, perform the initial configuration of Git by running the command below.

sudo apt install git
git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"

Install NodeBB

Now, we’re ready to install and set up NodeBB. First, create a new NodeBB account on the Ubuntu machine.

sudo adduser nodebb --disabled-password

Create a directory for NodeBB.

sudo mkdir /var/www/html/nodebb -p
sudo chown -R nodebb:nodebb /var/www/html/nodebb

Next, switch to the NodeBB user account, navigate to the directory, and clone all the NodeBB files using Git.

sudo su - nodebb
cd /var/www/html/nodebb

Clone NodeBB to the /var/www/nodebb directory. The dot at the end of the command refers to the current directory.

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

NodeBB ships with a command-line utility. Use the following command to install NodeBB.

./nodebb setup

Complete the prompts and wait for the installation to complete.

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 (ca8b716b-d793-4501-8db7-3a8a4f4f17ff)
Would you like to submit anonymous plugin usage to nbbpm? (yes)
Which database to use (mongo) postgres
2024-06-21T15:52:39.220Z [9899] - info:
Now configuring postgres database:
Host IP or address of your PostgreSQL instance (127.0.0.1)
Host port of your PostgreSQL instance (5432)
PostgreSQL username nodebbuser
Password of your PostgreSQL database
PostgreSQL database name (nodebb) nodebbdb
Enable SSL for PostgreSQL database access (false)
2024-06-21T15:53:21.697Z [9899] - info: [database] Checking database indices.
....................................................
Administrator username superadmin
Administrator email address superadmin@example.com
Password
Confirm Password
======================================================================

NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.

Once everything is done, you can start NodeBB using the command below.

./nodebb start

Then, open your browser and browse to the machine’s local host or IP address, followed by port number 4567.

http://localhost:4567

Run NodeBB as a System Service

To make NodeBB easier to manage, you can set it up as a system service. Then, use the systemctl command to manage it.

First, stop the NodeBB service.

./nodebb stop

Next, run the command below to create a NodeBB system service file.

sudo nano /etc/systemd/system/nodebb.service

Copy and paste the lines below in the file and save it.

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

[Service]
Type=simple
User=nodebb

StandardError=syslog
SyslogIdentifier=nodebb

Environment=NODE_ENV=production
WorkingDirectory=/var/www/html/nodebb
ExecStart=/usr/bin/env node loader.js --no-silent --no-daemon
Restart=always

[Install]
WantedBy=multi-user.target

Enable and start NodeBB.

sudo systemctl daemon-reload
sudo systemctl enable nodebb
sudo systemctl start nodebb
sudo systemctl status nodebb

The status option will display NodeBB as running and healthy.

nodebb.service - NodeBB
Loaded: loaded (/etc/systemd/system/nodebb.service; enabled; preset: enabl>
Active: active (running) since Fri 2024-06-21 11:07:42 CDT; 7s ago
Docs: https://docs.nodebb.org
Main PID: 12269 (node)
Tasks: 22 (limit: 4561)
Memory: 146.5M (peak: 146.9M)
CPU: 2.324s
CGroup: /system.slice/nodebb.service
├─12269 node loader.js --no-silent --no-daemon
└─12280 /usr/bin/node /var/www/html/nodebb/app.js

Every time you start up the machine, NodeBB should be accessible using the local server name or IP address followed by the port number.

Set up a reverse proxy

Now that NodeBB is set up, you can use a reverse proxy to ensure NodeBB is accessing via a domain name and optimize for web traffic.

The two links below show you how to set up a reverse proxy using Nginx or Apache.

That should do it!

Conclusion:

  • Installing NodeBB with Nginx on Ubuntu 24.04 enhances web traffic handling and security.
  • PostgreSQL installation and configuration provide a solid foundation for the NodeBB database.
  • Node.js installation ensures the functionality of the NodeBB forum platform.
  • Git setup is essential for utilizing and configuring NodeBB efficiently
  • Creating NodeBB as a systemd service streamlines management and ensures its availability
  • Implementation of a reverse proxy further optimizes web traffic and accessibility for NodeBB

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *