Back to Blog

Wiki.js Installation Guide (MariaDB + Node.js via NVM)

Overview

This guide explains how to install Wiki.js on a RHEL-based system (Rocky Linux, AlmaLinux, CentOS, Fedora) using:

  • MariaDB as the database
  • Node.js 22 installed via NVM
  • systemd service
  • Port 80 (no reverse proxy)

Prerequisites

  • Root or sudo access
  • Internet connectivity
  • Clean system recommended

1. System Preparation

Before starting, we update the system to ensure all security patches are applied and install basic utilities required for fetching files and editing configurations.

# Update system packages
sudo dnf update -y

# Install essential tools: wget (downloading), tar (extracting), curl (API/NVM), nano (editing)
sudo dnf install -y wget tar curl nano which

2. Install and Secure MariaDB

Wiki.js requires a database to store page content and configurations. MariaDB is a robust, open-source fork of MySQL that is highly compatible with RHEL.

2.1 Install MariaDB Server

sudo dnf install -y mariadb-server
sudo systemctl enable --now mariadb

2.2 Secure MariaDB

Run the security script to set a root password, remove anonymous users, and disallow remote root login. Follow the prompts carefully.

sudo mysql_secure_installation

3. Create Wiki.js Database and User

We need a dedicated database and a specific user with restricted permissions to interact with that database for better security.

# Log into MariaDB
sudo mysql -u root -p
-- Create the database with UTF8 support for international characters
CREATE DATABASE wikijs
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

-- Create a dedicated user for Wiki.js
CREATE USER 'wikiuser'@'localhost'
  IDENTIFIED BY 'your_password_here';

-- Grant permissions only to the wikijs database
GRANT ALL PRIVILEGES ON wikijs.*
  TO 'wikiuser'@'localhost';

FLUSH PRIVILEGES;
EXIT;

4. Install Node.js via NVM

Wiki.js is built on Node.js. Using NVM (Node Version Manager) allows us to install the specific version required (v22) without conflicting with system-level packages.

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc

# Install Node.js 22
nvm install 22

# Create a symbolic link so the systemd service can find the Node binary
sudo ln -sf $(which node) /usr/bin/node
sudo chmod +x /root

5. Create Wiki.js Service User

For security best practices, we run the Wiki.js application under its own non-privileged user account rather than root.

# Create a system user named 'wiki' with a home directory at /var/wiki
sudo useradd -r -m -d /var/wiki wiki

6. Download and Install Wiki.js

We fetch the latest production build of Wiki.js directly from their official GitHub releases.

cd /var/wiki
sudo wget https://github.com/requarks/wiki/releases/latest/download/wiki-js.tar.gz

# Extract the archive and prepare the configuration file
sudo tar xzf wiki-js.tar.gz
sudo cp config.sample.yml config.yml

# Ensure the 'wiki' user owns the application files
sudo chown -R wiki:wiki /var/wiki
sudo chmod -R 755 /var/wiki

7. Configure Wiki.js Database

We must point the application to the database we created earlier by editing the YAML configuration file.

sudo nano /var/wiki/config.yml

Update the port and db sections:

port: 80
db:
  type: mariadb
  host: localhost
  port: 3306
  user: wikiuser
  pass: your_password_here
  db: wikijs

8. Create systemd Service

To ensure Wiki.js starts automatically on boot and restarts if it crashes, we create a systemd service file. We include CAP_NET_BIND_SERVICE to allow the non-root user to listen on Port 80.

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

Paste the following:

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

[Service]
Type=simple
User=wiki
Group=wiki
WorkingDirectory=/var/wiki
ExecStart=/usr/bin/node /var/wiki/server
Restart=always
Environment=NODE_ENV=production
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

9. Start Wiki.js

Reload the systemd daemon to recognize the new service and start it up.

sudo systemctl daemon-reload
sudo systemctl enable --now wiki.service

# Check logs to ensure the server started correctly
sudo journalctl -u wiki.service -f

10. First-Time Setup

Once the service is running, navigate to your server’s IP address in a web browser. You will be greeted by the Wiki.js setup wizard where you will:

  1. Configure the administrator email and password.
  2. Set the site URL.
  3. Finalize the installation.

URL: http://your-server-ip