Oct 4, 2024 3 min read

Wikijs: Your Self-Hosting Setup and Management Guide

Wikijs: Your Self-Hosting Setup and Management Guide
Table of Contents

Wiki.js is a modern, open-source wiki application designed for ease of use, high levels of customization, and complete control over your data. It's a fantastic choice for self-hosting due to its robust feature set, support for various databases, and user-friendly interface. In this guide, we’ll walk through the process of deploying, configuring, and managing a self-hosted instance of Wiki.js, including installation, reverse proxy setup, logging, backups, and unique feature utilization.

Installing Wikijs

📦 Docker/Docker Compose Setup

Docker is the easiest and most efficient way to deploy Wiki.js. Below is a sample docker-compose.yml file to get started:


version: '3'

services:

wikijs:

image: requarks/wiki:latest

container_name: wikijs

restart: always

ports:

- "3000:3000"

volumes:

- ./data:/data

environment:

DB_TYPE: postgres

DB_HOST: db

DB_PORT: 5432

DB_USER: wikijs

DB_PASS: wikijs_password

DB_NAME: wiki

db:

image: postgres:13

container_name: wikijs-db

restart: always

environment:

POSTGRES_USER: wikijs

POSTGRES_PASSWORD: wikijs_password

POSTGRES_DB: wiki

volumes:

- ./db:/var/lib/postgresql/data

Save the above file as docker-compose.yml and bring the stack up using the following commands:


mkdir wikijs && cd wikijs

nano docker-compose.yml

docker-compose up -d

This will spin up Wiki.js and a PostgreSQL database. Access it via http://<your-server-ip>:3000.

🚀 Manual Installation

For manual installation on Linux:

  1. Install dependencies:

sudo apt update && sudo apt install -y curl git build-essential

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

sudo apt install -y nodejs

  1. Clone the Wiki.js repository and install:

git clone https://github.com/Requarks/wiki.git

cd wiki

npm install

  1. Configure Wiki.js by editing config.yml (you'll need to configure your database, port, etc.) and start the server:

node server

Access Wiki.js at http://<your-server-ip>:3000.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve Wiki.js via Nginx, create a new server block:


sudo nano /etc/nginx/sites-available/wikijs

Add the following configuration:


server {

listen 80;

server_name yourdomain.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;

}

}

Enable the configuration and reload Nginx:


sudo ln -s /etc/nginx/sites-available/wikijs /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

🔒 SSL/TLS Setup

Secure your Wiki.js instance with Let's Encrypt:


sudo apt install -y certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com

Automate certificate renewals by adding this to your crontab:


0 3 * * * certbot renew --quiet

🛠️ Testing and Reloading Nginx

Test your configuration and restart Nginx to apply changes:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Wikijs

🗃️ Enabling Debug Logs

Enable debug logs for Wiki.js by editing the config.yml file:


log:

level: debug

Restart your instance for the changes to take effect:


docker-compose restart wikijs

📄 Viewing Logs

If running via Docker, view logs with:


docker logs -f wikijs

For manual installations, check logs in ./logs/ or the directory specified in your config.yml.

🛠️ Troubleshooting Common Issues

  • Database Connection Errors: Ensure database credentials in config.yml match your setup.

  • Port Conflicts: Verify Wiki.js is running on an unused port or adjust the ports section in docker-compose.yml.

📤 Exporting Logs

Export logs to an ELK Stack by configuring Logstash or forwarding logs via syslog. For example, you can use Docker logging drivers:


docker run --log-driver=syslog --log-opt syslog-address=udp://<elk-server-ip>:514 requarks/wiki

Backup and Restore

🗂️ File-Based Backups

For Docker-based setups, backup the data and db directories:


tar -czvf wikijs-backup.tar.gz ./data ./db

🔄 Database Backups

Use pg_dump to back up the PostgreSQL database:


docker exec -t wikijs-db pg_dump -U wikijs -F c wiki > wikijs-db-backup.sql

Restore it with:


docker exec -i wikijs-db pg_restore -U wikijs -d wiki < wikijs-db-backup.sql

📅 Automated Backup Scripts

Set up a cron job for periodic backups:


crontab -e

Add the following line:


0 2 * * * docker exec -t wikijs-db pg_dump -U wikijs > /path/to/backups/wikijs-$(date +\%F).sql

Updating and Upgrading Wikijs

⬆️ Updating Docker Images

Update Wiki.js to the latest version with:


docker-compose pull

docker-compose up -d

🛠️ Manual Updates

If installed manually, pull the latest code and rebuild:


git pull

npm install

node server

🔍 Checking for Updates

Visit Wiki.js’s GitHub repository or documentation to verify the latest version. For Docker users, use:


docker images | grep requarks/wiki

Leveraging Wikijs’s Unique Features

🔧 Enabling APIs

Activate the API in config.yml:


api:

enabled: true

authentication: true

Access the API at http://<your-server-ip>:3000/api. For example, retrieve page details with curl:


curl -X GET "http://<your-server-ip>:3000/api/pages" -H "Authorization: Bearer <your-token>"

🌟 Advanced Configurations

Enable advanced features like authentication providers (e.g., LDAP, OAuth) in the admin panel under "Authentication". Alternatively, configure them directly in config.yml:


auth:

strategies:

- provider: google

clientId: <your-client-id>

clientSecret: <your-client-secret>

Wrapping Up

By following this guide, you've successfully deployed, configured, and secured a Wiki.js instance. With its robust feature set and customization options, Wiki.js provides full control over your documentation needs. Begin exploring its unique functionalities and make it your go-to self-hosted wiki solution!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.