Skip to main content

Lab 5.7 - Install Wiki.js on Ubuntu 24.04 LTS

Objectives​

By the end of this lab, you will be able to:

  • Install Git and Node.js on Ubuntu 24.04
  • Install and configure MariaDB
  • Download and configure Wiki.js
  • Create a systemd service for Wiki.js
  • Troubleshoot common installation issues
  • Configure HTTPS with Certbot

Prerequisites​

  • Ubuntu 24.04 LTS installed
  • Terminal access with sudo rights
  • Internet connection
  • At least 2 GB of available RAM
  • At least 5 GB of free disk space

Introduction​

This guide walks you through the installation of Wiki.js, a modern and powerful Wiki engine based on Node.js, Git, and Markdown. Wiki.js is distributed under the Affero GNU General Public License and supports multiple database management systems.


Part 1: Installing Git​

Wiki.js requires Git. To install it on Ubuntu 24.04, follow these steps:

# Switch to superuser mode
sudo -s
# or
su

# Update packages
sudo apt update

# Install Git
sudo apt install git -y

Verifying the installation​

git --version
# Should display: git version 2.x.x or higher

Part 2: Installing Node.js​

Wiki.js runs on Node.js. Install the LTS version of Node.js using the NodeSource script:

# Download and run the NodeSource installation script
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

# Install Node.js
sudo apt-get install -y nodejs

Verifying installed versions​

# Check Node.js version
node -v
# Should display: v20.x.x or higher (LTS version)

# Check npm version
npm -v
# Should display: 10.x.x or higher

Part 3: Installing and Configuring MariaDB​

Installing MariaDB​

Install MariaDB to manage Wiki.js data:

# Install MariaDB
sudo apt install mariadb-server mariadb-client -y

# Start the service
sudo systemctl start mariadb

# Enable the service at startup
sudo systemctl enable mariadb

# Check the status
sudo systemctl status mariadb

Connection test​

# Test connection with mariadb
mariadb
# Type exit; to quit

# Test connection with mysql
mysql
# Type exit; to quit

Securing MariaDB​

Harden the instance using the command:

sudo mariadb-secure-installation

Recommended responses:

Enter current password for root: [Press Enter]
Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Database configuration​

Connect to MariaDB and set up the database:

sudo mysql -u root -p

In the MariaDB shell, execute the following commands:

CREATE DATABASE wikidb;
CREATE USER 'wikidb_user'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikidb_user'@'localhost';
FLUSH PRIVILEGES;
SHOW DATABASES;
USE wikidb;
SHOW TABLES;
EXIT;

Note: Replace PASSWORD with a secure password of your choice.


Part 4: Downloading and Installing Wiki.js​

Create a user and folder for Wiki.js​

# Create a system user for Wiki.js
sudo adduser --system --group wikijs

# Create the installation directory
sudo mkdir -p /var/www/wikijs

# Verify creation
ls -la /var/www/

# Set the owner
sudo chown -R wikijs:wikijs /var/www/wikijs

# Verify permissions
ls -la /var/www/
ls -la /var/www/wikijs

Modify the wikijs user shell​

# Allow login with a bash shell
sudo usermod -s /bin/bash wikijs

Download and install Wiki.js​

# Log in as wikijs user
sudo su - wikijs

# Verify current directory
pwd
# Should display: /var/www/wikijs

# Verify user
whoami
# Should display: wikijs

# Go to the installation directory
cd /var/www/wikijs

# Download Wiki.js
wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz

# Extract the archive
tar xzf wiki-js.tar.gz

# Verify contents
ls -la

# Remove the archive
rm wiki-js.tar.gz

# Copy the sample configuration file
cp config.sample.yml config.yml

# Edit the configuration file
nano config.yml

Configuring the config.yml file​

Configure the config.yml file to use MariaDB. Modify the db section:

db:
type: mariadb
host: localhost
port: 3306
user: wikidb_user
pass: PASSWORD
db: wikidb
ssl: false

bindIP: 127.0.0.1
port: 3000

Important:

  • Replace PASSWORD with the password you set for wikidb_user
  • bindIP: 127.0.0.1 means Wiki.js will listen only on localhost
  • For external access, use bindIP: 0.0.0.0 (see Troubleshooting section #4)

Comment out unused sections:

In the config.yml file, comment out the sections for PostgreSQL and SQLite that are not used:

# Comment out these lines (add # at the beginning):
# sslOptions:
# auto: true
# # rejectUnauthorized: false

# # Optional - PostgreSQL only:
# schema: public

# # SQLite only:
# storage: path/to/database.sqlite

Save and exit with Ctrl + X, then Y, then Enter.


Part 5: Creating a systemd Service​

Return to root user​

Before creating the service, return to the main user:

# Exit wikijs session
exit

# Verify you are root
whoami
# Should display: root

Troubleshooting #1: Permissions to create the service​

If you encounter a permissions error while creating the service:

# If you are still wikijs
whoami
# Should display: wikijs

# Exit
exit
# or
sudo -s
# or
su

# Verify
whoami
# Should display: root

# Change wikijs password
sudo passwd wikijs

# Add wikijs to the sudo group
sudo usermod -aG sudo wikijs

# Reconnect as wikijs
su - wikijs

# Now you can use sudo
sudo nano /etc/systemd/system/wikijs.service

Create the systemd service​

# Create the service file
sudo nano /etc/systemd/system/wikijs.service

Add the following content:

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

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

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

[Install]
WantedBy=multi-user.target

Save and exit.

Enable and start the service​

# Reload systemd configuration
sudo systemctl daemon-reload

# Start the service
sudo systemctl start wikijs

# Enable the service at startup
sudo systemctl enable wikijs

# Check the status
sudo systemctl status wikijs

Part 6: Troubleshooting​

Troubleshooting #2: Check logs​

If the service does not start correctly, check the logs:

# View the last 50 lines of logs
sudo journalctl -u wikijs.service --no-pager --lines=50

# Follow logs in real-time
sudo journalctl -u wikijs.service -f

Problem 1: YAML indentation error - sslOptions​

Error:

bad indentation of a mapping entry at line 37, column 3:
sslOptions:
^

Solution:

# Go to the Wiki.js directory
cd /var/www/wikijs

# Edit the configuration file
nano config.yml

# Comment out the following lines (add # at the beginning):
# sslOptions:
# auto: true
# # rejectUnauthorized: false

# Save and exit

# Reload and restart the service
sudo systemctl daemon-reload
sudo systemctl start wikijs
sudo systemctl enable wikijs
sudo systemctl status wikijs

Problem 2: YAML indentation error - schema (PostgreSQL)​

Error:

bad indentation of a mapping entry at line 47, column 3:
schema: public
^

Solution:

cd /var/www/wikijs
nano config.yml

# Comment out the following lines:
# Optional - PostgreSQL only:
# schema: public

# Save and exit

# Reload and restart
sudo systemctl daemon-reload
sudo systemctl start wikijs
sudo systemctl enable wikijs
sudo systemctl status wikijs

Problem 3: YAML indentation error - storage (SQLite)​

Error:

bad indentation of a mapping entry at line 50, column 3:
storage: path/to/database.sqlite
^

Solution:

cd /var/www/wikijs
nano config.yml

# Comment out the following lines:
# SQLite only:
# storage: path/to/database.sqlite

# Save and exit

# Reload and restart
sudo systemctl daemon-reload
sudo systemctl start wikijs
sudo systemctl enable wikijs
sudo systemctl status wikijs

Problem 4: External access (Azure/Cloud)​

If you want to access Wiki.js from outside (e.g., from Azure):

  1. Add an inbound traffic rule in your cloud firewall (port 3000)

  2. Modify the bindIP in config.yml:

# Log in as wikijs
sudo su - wikijs

# Go to the directory
cd /var/www/wikijs

# Edit the configuration
nano config.yml

Change:

bindIP: 127.0.0.1

To:

bindIP: 0.0.0.0

Save and exit.

  1. Reload and restart the service:
# Return to root
exit

# Reload configuration
sudo systemctl daemon-reload

# Restart the service (important!)
sudo systemctl restart wikijs

# Check the status
sudo systemctl status wikijs
  1. Access Wiki.js:

Access Wiki.js via your browser using the URL: http://<IP_address>:3000


Part 7: Accessing Wiki.js​

Local access​

Access Wiki.js via your browser using the URL: http://127.0.0.1:3000 or http://localhost:3000

External access​

If you configured bindIP: 0.0.0.0, access via: http://<IP_address>:3000

Initial configuration​

  1. Follow the instructions to create an admin account
  2. Complete the installation via the web interface
  3. Log in with your admin credentials

Part 8: HTTPS Configuration with Certbot​

Installing Certbot​

# Connect via SSH (if on Azure/Cloud)
# ssh -i key1.pem azureuser@<your_vm_public_ip>

# Switch to root
sudo -i

# Update packages
sudo apt update

# Install Certbot and the Apache plugin
sudo apt install certbot python3-certbot-apache -y

Firewall configuration​

# Allow Apache (HTTP and HTTPS)
sudo ufw allow 'Apache Full'

# Check the status
sudo ufw status

Obtaining an SSL certificate​

# Obtain an SSL certificate with Certbot
sudo certbot --apache

During execution:

  • Enter your email address
  • Agree to the terms and conditions
  • Enter your domain name (e.g., haythemrehouma.eastus.cloudapp.azure.com)
  • Choose to redirect HTTP to HTTPS

Verify automatic renewal​

# Check the status of the Certbot timer
sudo systemctl status certbot.timer

# Test renewal (simulation)
sudo certbot renew --dry-run

Certbot will automatically renew certificates before expiration.


Summary of Important Commands​

CommandDescription
git --versionCheck Git version
node -v && npm -vCheck Node.js and npm versions
sudo systemctl status mariadbCheck MariaDB status
sudo mysql -u root -pConnect to MariaDB
sudo systemctl status wikijsCheck Wiki.js service status
sudo journalctl -u wikijs.service -fFollow logs in real-time
sudo systemctl restart wikijsRestart Wiki.js service
sudo certbot renew --dry-runTest SSL renewal

Final Verification​

Ensure you have successfully:

  • Installed Git and Node.js
  • Installed and configured MariaDB
  • Created the database and user for Wiki.js
  • Downloaded and extracted Wiki.js
  • Configured the config.yml file correctly
  • Created and enabled the systemd service
  • Accessed Wiki.js via the browser
  • Resolved YAML errors if present
  • Configured HTTPS with Certbot (optional)

Reflection Questions​

  1. Why is it important to create a dedicated system user (wikijs) for Wiki.js?

    • Explain the security benefits
  2. What is the difference between bindIP: 127.0.0.1 and bindIP: 0.0.0.0?

    • In which cases would you use each configuration?
  3. Why is it necessary to comment out the PostgreSQL and SQLite sections in config.yml if using MariaDB?

    • Explain YAML errors and how to avoid them
  4. What is the role of the systemd service in this installation?

    • Explain the advantages over manual startup
  5. Why use Certbot for HTTPS rather than a self-signed certificate?

    • What are the advantages for a production environment?

Next Steps​

  • Module 8: Services and Daemons (to deepen systemd knowledge)
  • Module 9: System Security (to further secure the installation)
  • TP 2: NGINX Reverse Proxy (to expose Wiki.js via a reverse proxy)

Additional Resources​


Lab created on: December 2024