Wiki.js is an open-source, lightweight wiki software. It is built on the Node.js JavaScript framework. It can be used to write documentation, wiki, and web content using a Markdown editor for developers and a WYSIWYG editor for non-technical people. It supports multiple content types including UML diagrams, Math expressions using Tex or MathML syntax, and code. It includes multiple modules for various functions including analytics, authentication, logging, third-party search engines, and multiple storage services to sync your content to.

In this tutorial, you will learn to install Wiki.js on a Ubuntu 22.04 server using the PostgreSQL database and Nginx server for proxying.

Prerequisites

  • A server running Ubuntu 22.04.

  • A non-root user with sudo privileges.

  • A fully qualified domain name (FQDN) pointing to your server. For our purposes, we will use wiki.example.com as the domain name.

  • Make sure everything is updated.

    $ sudo apt update && sudo apt upgrade
    
  • Install basic utility packages. Some of them may already be installed.

    $ sudo apt install wget curl ca-certificates gnupg gnupg2 nano unzip lsb-release ubuntu-keyring -y
    

Step 1 – Configure Firewall

Before installing any packages, the first step is configuring the firewall to allow HTTP and HTTPS connections.

Check the status of the firewall.

$ sudo ufw status

You should see something like the following.

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

Allow HTTP and HTTPs ports.

$ sudo ufw allow http
$ sudo ufw allow https

Check the status again to confirm.

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443                        ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)

Step 2 – Install PostgreSQL and Utilities

Ubuntu 22.04 ships with an older version of PostgreSQL. We will install Postgres 14 for our tutorial.

Install the repository for PostgreSQL.

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Import PostgreSQL GPG key.

$ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null

Update the system repository list.

$ sudo apt update

Install PostgreSQL 14 server.

$ sudo apt install -y postgresql-14

Check the status of the service.

$ sudo systemctl status postgresql
? postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Tue 2022-10-25 06:24:24 UTC; 10min ago
   Main PID: 4032 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Oct 25 06:24:24 wiki systemd[1]: Starting PostgreSQL RDBMS...
Oct 25 06:24:24 wiki systemd[1]: Finished PostgreSQL RDBMS.

Step 3 – Configure PostgreSQL

Log in to the PostgreSQL shell.

$ sudo -i -u postgres psql

Create a new database for Wiki.js.

postgres=# CREATE DATABASE wikidb;

Create a new database user with a strong password.

postgres=# CREATE USER wikiuser WITH ENCRYPTED PASSWORD 'wikipassword';

Grant the rights to the user to use the database.

postgres=# GRANT ALL PRIVILEGES ON DATABASE wikidb TO wikiuser;

Exit the Postgres Shell.

postgres=# q

Step 4 – Install Node.js

Wiki.js supports Node v16 at the moment of writing this tutorial.

Install the Node repository using the following command.

$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

Install Node.

$ sudo apt install nodejs -y

Verify Node installation.

$ node --version
v16.18.0

Step 5 – Download Wiki.js

Create a folder to install Wiki.js.

$ sudo mkdir -p /var/www/wikijs

Set the currently logged-in user as the owner of the folder.

$ sudo chown $USER:$USER /var/www/wikijs

Switch to the directory and download the Wiki.js code archive.

$ cd /var/www/wikijs && wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz

Extract the downloaded archive.

$ tar xzf wiki-js.tar.gz

Delete the archive.

$ rm wiki-js.tar.gz

Step 6 – Configure and Run Wiki.js

Create the configuration file from the sample.

$ cp config.sample.yml config.yml

Open the configuration file for editing.

$ nano config.yml

Find the following database settings and update their values with the ones configured in step 3.

# PostgreSQL / MySQL / MariaDB / MS SQL Server only:
host: localhost
port: 5432
user: wikiuser
pass: wikipassword
db: wikidb
ssl: false

Find the line bindIP: 0.0.0.0 and update it as follows.

bindIP: 127.0.0.1

This will make WIki.js listen on the loopback address because we will be using the Nginx proxy to access it from the outside.

Save the file by pressing Ctrl X and entering Y when prompted.

Run Wiki.js by using the following command.

$ node server

You will receive a similar output confirming a successful install.

Loading configuration from /var/www/wikijs/config.yml... OK
2022-10-25T06:40:46.294Z [MASTER] info: =======================================
2022-10-25T06:40:46.296Z [MASTER] info: = Wiki.js 2.5.289 =====================
2022-10-25T06:40:46.296Z [MASTER] info: =======================================
2022-10-25T06:40:46.296Z [MASTER] info: Initializing...
2022-10-25T06:40:46.962Z [MASTER] info: Using database driver pg for postgres [ OK ]
2022-10-25T06:40:46.974Z [MASTER] info: Connecting to database...
2022-10-25T06:40:47.067Z [MASTER] info: Database Connection Successful [ OK ]
2022-10-25T06:40:47.345Z [MASTER] warn: DB Configuration is empty or incomplete. Switching to Setup mode...
2022-10-25T06:40:47.345Z [MASTER] info: Starting setup wizard...
2022-10-25T06:40:47.510Z [MASTER] info: Starting HTTP server on port 3000...
2022-10-25T06:40:47.511Z [MASTER] info: HTTP Server on port: [ 3000 ]
2022-10-25T06:40:47.515Z [MASTER] info: HTTP Server: [ RUNNING ]
2022-10-25T06:40:47.515Z [MASTER] info: .......................................................................
2022-10-25T06:40:47.515Z [MASTER] info: 
2022-10-25T06:40:47.516Z [MASTER] info: Browse to http://YOUR-SERVER-IP:3000/ to complete setup!
2022-10-25T06:40:47.516Z [MASTER] info: 
2022-10-25T06:40:47.516Z [MASTER] info: ........................................................................

Press Ctrl C to stop the process.

Step 7 – Setup a Systemd Service

The above process to keep Wiki.js running is temporary. To make the process permanent, we will need to create a systemd service for Wiki.js to run it as a background service. This will allow Wiki.js to run across system reboots.

Create a systemd service file for Wiki.js and open it for editing.

$ sudo nano /etc/systemd/system/wikijs.service

Paste the following code in it. Replace the value of the variable User with the name of your system user.

[Unit]
Description=Wiki.js
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always

User=navjot
Environment=NODE_ENV=production
WorkingDirectory=/var/www/wikijs

[Install]
WantedBy=multi-user.target

Save the file by pressing Ctrl X and entering Y when prompted.

Reload the system daemon.

$ sudo systemctl daemon-reload

Enable the Wiki.js service.

$ sudo systemctl enable wikijs

Step 8 – Install Nginx

Ubuntu 22.04 ships with an older version of Nginx. You need to download the official Nginx repository to install the latest version.

Import the official Nginx key.

$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor 
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Set up the official repository for Nginx.

$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] 
  http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" 
    | sudo tee /etc/apt/sources.list.d/nginx.list

Pin the repository to give preference to the official repo over Ubuntu one.

$ echo -e "Package: *nPin: origin nginx.orgnPin: release o=nginxnPin-Priority: 900n" 
     | sudo tee /etc/apt/preferences.d/99nginx

Update the system repository list.

$ sudo apt update

Install the Nginx server.

$ sudo apt install nginx -y

Verify the installation.

$ nginx -v
nginx version: nginx/1.22.1

Start the Nginx server.

$ sudo systemctl start nginx

Check the status of the service.

$ sudo systemctl status nginx
? nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-10-25 06:50:05 UTC; 2s ago
       Docs: https://nginx.org/en/docs/
    Process: 5522 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
   Main PID: 5523 (nginx)
      Tasks: 2 (limit: 1030)
     Memory: 1.8M
        CPU: 4ms
     CGroup: /system.slice/nginx.service
             ??5523 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
             ??5524 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Oct 25 06:50:05 wiki systemd[1]: Starting nginx - high performance web server...

Step 9 – Install SSL

We need to install Certbot to generate the SSL certificate. You can either install Certbot using Ubuntu’s repository or grab the latest version using the Snapd tool. We will be using the Snapd version.

Ubuntu 22.04 comes with Snapd installed by default. Run the following commands to ensure that your version of Snapd is up to date.

$ sudo snap install core
$ sudo snap refresh core

Install Certbot.

$ sudo snap install --classic certbot

Use the following command to ensure that the Certbot command can be run by creating a symbolic link to the /usr/bin directory.

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

Run the following command to issue the certificate.

$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email protected] -d wiki.example.com

The above command will download a certificate to the /etc/letsencrypt/live/wiki.example.com directory on your server.

Generate a Diffie-Hellman group certificate.

$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096

Check the Certbot renewal scheduler service.

$ sudo systemctl list-timers

You will find snap.certbot.renew.service as one of the services scheduled to run.

NEXT                        LEFT          LAST                        PASSED    UNIT                           ACTIVATES             

.................................................................................................................................
Tue 2022-10-25 00:00:00 UTC 17h left      Tue 2022-10-25 04:49:20 UTC 2h ago    logrotate.timer                logrotate.service
Tue 2022-10-25 02:39:09 UTC 20h left      Tue 2022-10-25 06:47:33 UTC 12min ago apt-daily.timer                apt-daily.service
Tue 2022-10-25 06:02:00 UTC 8h left       n/a                         n/a       snap.certbot.renew.timer       snap.certbot.renew.service

Do a dry run of the process to check whether the SSL renewal is working fine.

$ sudo certbot renew --dry-run

If you see no errors, you are all set. Your certificate will renew automatically.

Step 10 – Configure Nginx

Create and open the file /etc/nginx/conf.d/wikijs.conf for editing.

$ sudo nano /etc/nginx/conf.d/wikijs.conf

Paste the following code in it.

# enforce HTTPS
server {
  listen 80;
  listen [::]:80;
  server_name wiki.example.com;
  return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name wiki.example.com;

    root /var/www/wikijs;

    access_log  /var/log/nginx/wiki.access.log;
    error_log   /var/log/nginx/wiki.error.log;

    http2_push_preload on; # Enable HTTP/2 Server Push

    ssl_certificate /etc/letsencrypt/live/wiki.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wiki.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/wiki.example.com/chain.pem;
    ssl_session_timeout 1d;

    # Enable TLS versions (TLSv1.3 is required upcoming HTTP/3 QUIC).
    ssl_protocols TLSv1.2 TLSv1.3;

    # Enable TLSv1.3's 0-RTT. Use $ssl_early_data when reverse proxying to
    # prevent replay attacks.
    #
    # @see: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data
    ssl_early_data on;

    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384';
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:50m;

    # OCSP Stapling ---
    # fetch OCSP records from URL in ssl_certificate and cache them
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    add_header X-Early-Data $tls1_3_early_data;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_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://127.0.0.1:3000;
    }
}

# This block is useful for debugging TLS v1.3. Please feel free to remove this
# and use the `$ssl_early_data` variable exposed by NGINX directly should you
# wish to do so.
map $ssl_early_data $tls1_3_early_data {
  "~." $ssl_early_data;
  default "";
}

Replace the root location in the above file with the directory on your server.

Save the file by pressing Ctrl X and entering Y when prompted.

Open the file /etc/nginx/nginx.conf for editing.

$ sudo nano /etc/nginx/nginx.conf

Add the following line before the line include /etc/nginx/conf.d/*.conf;.

server_names_hash_bucket_size  64;

Save the file by pressing Ctrl X and entering Y when prompted.

Verify your Nginx configuration.

$ sudo nginx -t

If you see no errors, it means you are good to go.

Start the Wiki.js service.

$ sudo systemctl start wikijs

Reload the Nginx server.

$ sudo systemctl reload nginx

Step 11 – Finish the Installation

Visit the URL https://wiki.example.com to finish the installation.

<img alt="Wiki.js Setup Page" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/02/echo/wikijs-setup-page.png63f78b7ac63eb.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="736" loading="lazy" referrerpolicy="no-referrer" src="data:image/svg xml,” width=”750″>

Fill in your administrator account details and the URL. Disable Telemetry by unchecking the Allow Telemetry option. You can disable it from the Administration panel as well. Click the Install button to proceed.

You will be taken to the login page.

<img alt="Wiki.js Login Page" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/02/echo/wikijs-login-page.png63f78b7b2393f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="556" loading="lazy" referrerpolicy="no-referrer" src="data:image/svg xml,” width=”699″>

Enter your account details and click the Log in button to proceed to the administration page.

<img alt="Wiki.js Administration Page" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/02/echo/wikijs-admin-page.png63f78b7b51888.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="432" loading="lazy" referrerpolicy="no-referrer" src="data:image/svg xml,” width=”750″>

You can now start using Wiki.js.

Conclusion

This concludes our tutorial, where you learned how to install Wiki.js on a Ubuntu 22.04 server. If you have any questions, post them in the comments below.