Install October CMS on FreeBSD 13.0

Updated on November 21, 2023
Install October CMS on FreeBSD 13.0 header image

Introduction

This article will teach you how to install Wiki.JS, a Node.JS open-source wiki software, on Debian 11, with Nginx and PostgreSQL.

Prerequisites

You need two things to complete this tutorial :

  • A server running on Debian 11. You should be logged in as a non-root user with Sudo privileges.

  • If you want to connect your application to a domain name, you will need to have purchased a domain name and have DNS access. Have an A field open in your DNS with the following configuration:

  • Host Name: wiki

  • Type: A

  • TTL: 3600

  • Data: [Your server's IP address]

We will use the wiki subdomain in this tutorial, but you can use another configuration. We also will use a few placeholders that you will need to replace based on your setup:

  • Domain Name: wiki.example.com
  • New Debian and database user: dbuser
  • Database & Debian new user password: dbpwd

Install Node.js with NVM

The first step is to install the client URL for Debian. Install CURL with the following command:

$ sudo apt install curl -y 

You can now install Node.js. To make it more flexible, you will use the Node Version Manager to change the version of NodeJS at any time in the future.

$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

To access the nvm script, restart your terminal or reload it with this command:

$ source ~/.bashrc

You can see all the versions of Node.js available with this command:

$ nvm list-remote

...
v16.6.2
v16.7.0
v16.8.0
v16.9.0
v16.9.1
v16.10.0
v16.11.0
v16.11.1
v16.12.0
v16.13.0   (LTS: Gallium)
v16.13.1   (LTS: Gallium)
v16.13.2   (Latest LTS: Gallium)
v17.0.0
v17.0.1
v17.1.0
v17.2.0
v17.3.0
v17.3.1
v17.4.0
...

In this tutorial, you will install the latest recommended version of Node.js, 16.13.2 (Gallium). Depending on when you read this tutorial, you can install a newer LTS version.

Install the Latest LTS version:

$ nvm install v16.13.2

To be sure that Node.js is properly installed, run this command:

$ node -v

v16.13.2

Node.js is installed with its package manager, NPM. To make sure it was installed correctly, run this command:

$ npm -v

8.1.2

Install PostgreSQL

Now, you will install the recommended database for Wiki.js: PostgreSQL. Run the following command:

$ sudo apt install postgresql postgresql-contrib

The postgresql-contrib package adds some additional utilities and features.

Once the installation complete, your terminal will indicate the command to start your database:

Success. You can now start the database server using:

    **pg_ctlcluster 13 main start**

Ver Cluster Port Status Owner    Data directory              Log file
13  main    5432 down   postgres /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log

Run the command (It may be different from the one presented in this tutorial):

$ pg_ctlcluster 13 main start

You can connect to the database with the postgres account created during installation:

$ sudo -u postgres psql

The -u postgres flag specifies with which user to launch the psql command.

You can quit postgreSQL with the following command:

postgres=# \q

Create postgres user

Now, you will configure PostgreSQL. Start by creating a new database user

$ sudo -u postgres createuser --interactive

Enter name of role to add: dbuser

Leave as is or replace the dbuser username.

Shall the new role be a superuser? (y/n)

Hit Y then Enter.

Create postgres databases

Now, you have to create two databases. The default one for the user dbuser and another for Wiki.js.

Run the following commands:

$ sudo -u postgres createdb dbuser
$ sudo -u postgres createdb wiki

Create new Debian user and passwords

Once postgres user and databases are created, create a new Debian user with the same name as postgres:

$ sudo adduser dbuser

Adding user `dbuser' ...
Adding new group `dbuser' (1002) ...
Adding new user `dbuser' (1002) with group `dbuser' ...
Creating home directory `/home/dbuser' ...
Copying files from `/etc/skel' ...      
New password: dbpwd
Retype new password: dbpwd
...

Replace dbpwd with a strong password that suits you. Don't forget to store it somewhere for later.

...
passwd: password updated successfully
Changing the user information for test
Enter the new value, or press ENTER for the default
    Full Name []: 
    Room Number []: 
    Work Phone []:
    Home Phone []:
    Other []: 
Is the information correct? [Y/n]

Hit Y then Enter.

Now, connect again to the database:

$ sudo -u postgres psql

Change the database user (dbuser) password with the Debian one (dbpwd).

postgres=# \password dbuser

Enter new password: dbpwd
Enter it again: dbpwd

PostgreSQL is now ready for what is next!

Install Wiki.JS

First, go to your user directory or another one that suits you better:

$ cd ~

Then install another HTTP Client, Wget:

$ sudo apt install wget

Once installed, you can download Wiki.js on your machine with the following command:

$ wget https://github.com/Requarks/wiki/releases/download/2.5.272/wiki-js.tar.gz

Create a new directory to extract and install Wiki.js:

$ mkdir wiki

$ tar xzf wiki-js.tar.gz -C ./wiki

Once extracted, go in your app directory:

$ cd wiki

Rename the file "config.sample.yml" into "config.yml":

$ mv config.sample.yml config.yml

Then open config.yml to change some settings:

$ nano config.yml

Find the following block and change the username et the password:

...
# PostgreSQL / MySQL / MariaDB / MS SQL Server only:
host: localhost
port: 5432
user: dbuser
pass: dbpwd
db: wiki
ssl: false
...

Save the file by pressing Ctrl+X, then Y.

Install Nginx and configure Reverse Proxy

Now that your application is launched on your machine, install and configure Nginx to create HTTP access.

Your app runs and listens on localhost. When a request is made from outside the server, using a domain name, it is made to port 80 of your machine (port of the Nginx web server). But the application Wiki.js runs on port 3000 by default. Nginx has a Proxy role. It redirects requests to the service (Node.js application) assigned to the configured domain name. You need to configure Nginx to tell it that your domain name wiki.example.com corresponds to the Wiki.js application, localhost:3000.

To install Nginx on your server, run the following command:

$ sudo apt install nginx -y

To automatically launch Nginx when your server starts, run the following command:

$ sudo systemctl enable nginx

Before configuring Nginx, make sure your firewall is enabled and configured. First, turn on your firewall if you haven't already.

$ sudo ufw enable

Then allow Nginx in the firewall:

$ sudo ufw allow 'Nginx Full'
or
$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw allow 'Nginx HTTPS'

Warning! If you are connected to your server via SSH, and you have activated the firewall for the first time, you must add "ssh" or port 20 to the firewall.

$ sudo ufw allow 'ssh'
or
$ sudo ufw allow 22

Once the firewall is configured, create the Nginx configuration for your domain name.

$ sudo nano /etc/nginx/sites-available/wiki.example.com

Write this in the file:

server {
  listen 80;
  listen [::]:80;
        
  server_name wiki.example.com;
        
  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

The "listen" fields indicate the listening port of Nginx. The first relates to IPV4 and the second to IPV6. Unless specifically configured, specify port 80.

The "server_name" field contains all the domain names that you attach to the configured application.

The "location" block indicates two things. The first, at "/", is the URL's path that gives access to your application. In this example, it is "http://wiki.example.com/", the root of your domain name, which give access to the application indicated in our configuration file.

Next, inside the "location" block is a "proxy_pass" field. The proxy_pass field is the local link of the application http://localhost:[PORT]. Remember, the application is running under port 3000, so the link is "http://localhost:3000".

Save the file by pressing Ctrl+X, then Y, then check the syntax errors with the following command:

$ sudo nginx -t

Now, import your configuration into the /etc/nginx/sites-enabled folder with this command:

$ sudo ln -s /etc/nginx/sites-available/wiki.example.com /etc/nginx/sites-enabled

Finally, restart Nginx.

$ sudo service nginx restart
or
$ sudo systemctl restart nginx

Upgrade your connection with Let's Encrypt.

Currently, you can access your application over HTTP. But to secure the connection between the client and the server, you need to improve the protocol by changing it to HTTPS. To do this, install Certbot, a service that will generate and install Let's Encrypt SSL certificates for you.

You will need to install another package manager, Snap:

$ sudo apt install snapd

$ sudo snap install core; sudo snap refresh core

Then, you can install Certbot on your machine with the following commands:

$ sudo snap install --classic certbot

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

Once certbot is installed, request SSL certificates for your application:

$ sudo certbot --nginx

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: wiki.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Now, select the domain name you want to secure ("wiki.example.com").

$ Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): 1

In this example, select the number 1 and press ENTER.

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/wiki.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/wiki.example.com/privkey.pem
This certificate expires on ...
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
    
Deploying certificate
Successfully deployed certificate for wiki.example.com to /etc/nginx/sites-enabled/wiki.example.com
Your existing certificate has been successfully renewed, and the new certificate has been installed.
    
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
* Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Certbot modify your Nginx configuration file automatically. You don't have to change it to enable HTTPS. Just be aware that certificates generated by Certbot have an expiration date. Certbot will most certainly have asked for your email address. You will receive an email alerting you of the expiration of your certificate a few weeks before the deadline. You only have to repeat the following command to regenerate and reinstall a certificate.

$ sudo certbot --nginx

PM2

To start Wiki.js, you will use a process manager, PM2. It will allow you to run the app in the background of your system. To install it, run the following command:

$ npm install pm2 -g

Now, in the app directory, you can run your application with the following command:

$ pm2 start server --name wiki

BUT, I advise you to launch your application in the classic way to initialize your application and see if you have any errors:

$ node server

Loading configuration from /home/dev/wiki/config.yml... OK
2022-01-27T21:21:25.298Z [MASTER] info: =======================================
2022-01-27T21:21:25.299Z [MASTER] info: = Wiki.js 2.5.272 =====================
2022-01-27T21:21:25.299Z [MASTER] info: =======================================
2022-01-27T21:21:25.299Z [MASTER] info: Initializing...
2022-01-27T21:21:25.909Z [MASTER] info: Using database driver pg for postgres [ OK ]
2022-01-27T21:21:25.912Z [MASTER] info: Connecting to database...
2022-01-27T21:21:25.930Z [MASTER] info: Database Connection Successful [ OK ]
2022-01-27T21:21:26.106Z [MASTER] warn: DB Configuration is empty or incomplete. Switching to Setup mode...
2022-01-27T21:21:26.106Z [MASTER] info: Starting setup wizard...
2022-01-27T21:21:26.227Z [MASTER] info: Starting HTTP server on port 3000...
2022-01-27T21:21:26.227Z [MASTER] info: HTTP Server on port: [ 3000 ]
2022-01-27T21:21:26.230Z [MASTER] info: HTTP Server: [ RUNNING ]
2022-01-27T21:21:26.230Z [MASTER] info: 判判判判判判判判判判判判判判判判判判判判判判判判判判判判判
2022-01-27T21:21:26.230Z [MASTER] info:
2022-01-27T21:21:26.230Z [MASTER] info: Browse to http://YOUR-SERVER-IP:3000/ to complete setup!
2022-01-27T21:21:26.231Z [MASTER] info:
2022-01-27T21:21:26.231Z [MASTER] info: 伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴伴

You will access to your application on your browser with the url https://wiki.example.com. A page should open for creating the admin user.

Once achieved, you can stop your app by hitting Ctrl+C in your terminal.

Now, launch your application with PM2

$ pm2 start server --name wiki

you can stop the application with the name of the file:

$ pm2 stop wiki

To start your application, you can now use this shorter command:

$ pm2 start wiki

And to restart your application, run this command:

$ pm2 restart wiki

Conclusion

In this tutorial, you have successfully installed Wiki.js on your machine, with Node.js, Nginx, and PostgreSQL.

You can deepen this tutorial by going to the official documentation of the technologies presented here: