How to build a forum

Practically every online community has a forum. It makes sense though because forums are a great way to facilitate online discussion. Now let’s say that you wanted to build your own online forum. Well, building a very basic forum wouldn’t be too complicated. Just script together some PHP with an MYSQL database and you will be all set. Unfortunately, this would likely leave you vulnerable to many potential security holes and a terrible user experience. Plus, you would have to code a whole lot of extra functionality just to match the expectations of today’s modern forums.

So do yourself a favor and don’t reinvent the wheel unless you just want a good programming exercise. There are many good open source projects that can serve as a boilerplate for your forum. In this article, we will take a look at using NodeBB in order to build your own forum. It is built using NodeJS and MongoDB. So let’s take a look at how to build a forum.

Requirements:

  • Linux (Preferably Ubuntu)
  • NodeJS
  • MongoDB

Step 1: Installing NodeJS

Let’s start with installing the latest version of NodeJS. To do this, you will need to do the following:

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

This will install NodeJS version 8 to your system.

Step 2: Installing MongoDB

To install MongoDB on Ubuntu, you can follow the instructions on their website or use the instructions below if you are running Ubuntu 16.04.

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org

You also need to make a data directory for MongoDB. By default it’s at /data/db

sudo mkdir /data

sudo mkdir /data/db

Finally, you can start the service:

sudo service mongod start

Step 3: Configuring MongoDB

You will need to set up an admin account in MongoDB.

Enter mongo by typing in the following:

mongo

Then switch to the admin database (it will automatically create it for you)

use admin

Then type in the following:

db.createUser({user: "dave",pwd: "1234",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})

Next, we need to create a table for NodeBB. Switch to the NodeBB table:

use nodebb

Then type in the following to set up an admin in this table. You must keep the user ad nodebb:

db.createUser({ user: "nodebb", pwd: "abcd", roles: [ { role: "readWrite", db: "nodebb" },{ role: "clusterMonitor", db: "admin"}]})

Finally, type in:

quit()

Step 4:  Securing MongoDB

Although we configured ad admin user, we have yet to enable a secure sign on for MongoDB. This can be easily configured by editing the mongod.conf file and appending the following:

sudo nano etc/mongod.conf

Add tfollowinging line:

security:
   authorization: "enabled"

Then hit CRTL + O to save and CRTL + X to exit. Finally, restart MongoDB:

sudo service mongod restart

You should be able to sign in to Mongo now using your username and password:

mongo -u your_username -p your_password --authenticationDatabase=admin

Step 5: Install NodeBB

It’s finally time to install MongoDB.

First, make sure you have git installed along with the build-essential tools:

sudo apt-get install -y git build-essential

Go into any directory that you want and clone the repo:

git clone -b v1.5.x https://github.com/NodeBB/NodeBB.git $HOME/nodebb

Now type in the following:

cd nodebb

npm install --production
./nodebb setup

This will begin installing the required components. Once it’s done you can start the service:

/.nodebb start

To stop the service you can type in the following:

./nodebb stop

By default, it is running on port 4567. So to access your new forum you can go to http://localhost:4567 .

That’s it! You will now be in your working forum that gives you lots of customizability along with admin controls and user registration.

Further Considerations

It might be a good idea to put the server behind Nginx or Apache. That way you can do things like enable SSL. I am not going to cover it here, but the general idea isn’t too hard. Simple forward an apache or Nginx port to the locally running port on your computer.