How To Install Wiki.js on CentOS 7 / RHEL 7

Posted on 16 views

This guide will take you through the steps to install Wiki.js NodeJS Wiki Application on CentOS 7 / RHEL 7. Wiki.js is an open source, modern and powerful wiki app built on Node.js, Git, and Markdown. Wiki.js runs on Linux, macOS and Windows operating systems.

In Wiki.js, you write all content in the widely used and simple Markdown format, using the built-in visual editor. The content is directly saved into Markdown (.md) files and automatically synced with your remote Git repository. All your content is readable directly from your Git repository.

Features of Wiki.js

  • Beautifully designed for the modern web
  • Edit content in simple Markdown format
  • Has Integrated Access Control – Local database or external authentication providers like Microsoft Account, Google ID, Facebook, GitHub, Slack or LDAP (Active Directory).
  • Has Intuitive Assets Management
  • Lightweight and extremely powerful
  • Wiki.js has a built-in search engine
  • It is free to use and open-source

Server Requirements

  • Node.js
  • MariaDB database server
  • Git
  • Redus cache
  • A Git-compliant repository (public or private) (optional)

Note that the version of git available on CentOS 7 repository is a bit old, install the latest version of git using the guide:

Confirm Git is installed:

$ git --version
git version 2.36.0

Step 1: Install Node.js and dependencies

Add Node.js repo and install dependency packages.

curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install -y nodejs nginx gcc-c++ make  git vim wget curl unzip socat nginx httpd

Install and start Redis server

sudo yum -y install epel-release
sudo yum -y install redis
sudo systemctl enable --now redis

You can check if redis service is active by running the commands below:

$ systemctl status redis
 redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Mon 2022-06-20 20:12:05 UTC; 7s ago
 Main PID: 10765 (redis-server)
   CGroup: /system.slice/redis.service
           └─10765 /usr/bin/redis-server 127.0.0.1:6379

Jun 20 20:12:05 centos7.example.io systemd[1]: Starting Redis persistent key-value database...
Jun 20 20:12:05 centos7.example.io systemd[1]: Started Redis persistent key-value database.

Step 2: Install MariaDB Database

Wiki.js stores administrative data such as users, permissions and assets metadata in a SQL database. The article contents and uploads are not stored in the DB. Instead, they are stored on-disk and synced automatically with a remote git repository of your choice.

Run the following commands to install latest stable release of MariaDB database server on CentOS 7 / RHEL 7:

curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s --
sudo yum -y install MariaDB-server MariaDB-client MariaDB-backup

Start and enable mariadb database service

sudo systemctl enable  --now mariadb

Harden your database server installation:

$ sudo mariadb-secure-installation
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Create database user and db.

$ mysql -u root -p
CREATE DATABASE wikijs;
GRANT ALL PRIVILEGES ON wikijs.* TO 'wikijs'@'localhost' IDENTIFIED BY 'WikiDBPassw0rd';
FLUSH PRIVILEGES;
QUIT;

Step 3: Download Wiki.js on CentOS 7 / RHEL 7

We’ll need a dedicated system user for running Wiki.js application. Let’s first create this user.

sudo groupadd --system wikijs
sudo useradd -s /sbin/nologin --system -g wikijs wikijs

Create a project directory

sudo mkdir /var/www/wikijs

Download Wikijs latest release archive

VERSION=$(curl -s https://api.github.com/repos/Requarks/wiki/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/v//')
wget https://github.com/requarks/wiki/releases/download/v$VERSION/wiki-js.tar.gz

Extract downloaded file

sudo tar zxf wiki-js.tar.gz -C /var/www/wikijs

Create Wiki configuration file

sudo cp  /var/www/wikijs/config.sample.yml,config.yml

Step 4: Configure Wiki.js on CentOS 7 / RHEL 7

Modify the config file and fill in your database, redis and port settings:

$ sudo vim /var/www/wikijs/config.yml
db:
  type: mariadb

  # PostgreSQL / MySQL / MariaDB / MS SQL Server only:
  host: localhost
  port: 3306
  user: wikijs
  pass: WikiDBPassw0rd
  db: wikijs
  ssl: false

Test your configurations by running Wiki.js:

sudo node server

Expected output:

Loading configuration from /var/www/wikijs/config.yml... OK
2022-06-20T20:18:34.916Z [MASTER] info: =======================================
2022-06-20T20:18:34.919Z [MASTER] info: = Wiki.js 2.5.284 =====================
2022-06-20T20:18:34.919Z [MASTER] info: =======================================
2022-06-20T20:18:34.919Z [MASTER] info: Initializing...
2022-06-20T20:18:36.073Z [MASTER] info: Using database driver mysql2 for mariadb [ OK ]
2022-06-20T20:18:36.078Z [MASTER] info: Connecting to database...
2022-06-20T20:18:36.128Z [MASTER] info: Database Connection Successful [ OK ]
2022-06-20T20:18:38.691Z [MASTER] warn: DB Configuration is empty or incomplete. Switching to Setup mode...
2022-06-20T20:18:38.692Z [MASTER] info: Starting setup wizard...
2022-06-20T20:18:39.033Z [MASTER] info: Starting HTTP server on port 3000...
2022-06-20T20:18:39.033Z [MASTER] info: HTTP Server on port: [ 3000 ]
2022-06-20T20:18:39.039Z [MASTER] info: HTTP Server: [ RUNNING ]
2022-06-20T20:18:39.040Z [MASTER] info: 🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻
2022-06-20T20:18:39.040Z [MASTER] info:
2022-06-20T20:18:39.040Z [MASTER] info: Browse to http://YOUR-SERVER-IP:3000/ to complete setup!
2022-06-20T20:18:39.040Z [MASTER] info:
2022-06-20T20:18:39.040Z [MASTER] info: 🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺

Now configure Wiki.js application to run as a service.

sudo tee /etc/systemd/system/wiki.service<

Create extra directories needed and give user permissions for the directory.

sudo mkdir  /var/www/wikijs/data/uploads
sudo mkdir  /var/www/wikijs/data/cache
sudo chown -R wikijs:nginx /var/www/wikijs

Configure SELinux labels:

# allow httpd to can network relay
sudo setsebool -P httpd_can_network_connect 1

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/wikijs(/.*)?"
sudo restorecon -Rv /var/www/wikijs

Reload systemd and start service.

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

Confirm service status

$ systemctl status wiki
● wiki.service - Wiki.js
   Loaded: loaded (/etc/systemd/system/wiki.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-06-20 20:22:36 UTC; 9s ago
 Main PID: 10912 (node)
   CGroup: /system.slice/wiki.service
           └─10912 /usr/bin/node server

Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.007Z [MASTER] warn: DB Configuration is empty or incomplete. Switching to Setup mode...
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.008Z [MASTER] info: Starting setup wizard...
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.172Z [MASTER] info: Starting HTTP server on port 3000...
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.172Z [MASTER] info: HTTP Server on port: [ 3000 ]
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.176Z [MASTER] info: HTTP Server: [ RUNNING ]
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.176Z [MASTER] info: 🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.176Z [MASTER] info:
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.176Z [MASTER] info: Browse to http://YOUR-SERVER-IP:3000/ to complete setup!
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.177Z [MASTER] info:
Jun 20 20:22:38 centos7.example.io node[10912]: 2022-06-20T20:22:38.177Z [MASTER] info: 🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺

The service should bind to TCP port 3000:

$ sudo ss -tunelp | grep 3000
tcp    LISTEN     0      128       *:3000                  *:*                   users:(("node",pid=10912,fd=19)) uid:994 ino:55143 sk:ffff99644fffe6c0 <->

Step 5: Configure Wiki.js Nginx Proxy

Create Nginx configuration file

sudo vim /etc/nginx/conf.d/wikijs.conf

For http connection without ssl, add:

server 
    listen      80;
    server_name wiki.example.com;

    location / 
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_next_upstream error timeout http_502 http_503 http_504;
    

If you have firewalld service running, allow the service.

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

Configure SELinux:

sudo semanage port -a -t http_port_t -p tcp 3000
sudo setsebool -P httpd_can_network_connect 1

Configure Nginx HTTPS

The following configuration snippet is for http and https, but with a redirect from http to https.

# Redirect http to https
server 
    listen      80;
    server_name wiki.example.com;
    return      301 https://$server_name$request_uri;


# Serve https traffic

server 
    listen 443 ssl http2;
    server_name  wiki.example.com;

    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/wiki.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wiki.example.com/privkey.pem;
    ssl_session_timeout 5m;
    ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / 
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_next_upstream error timeout http_502 http_503 http_504;
    

Restart nginx service and ensure it is set to start on boot

sudo systemctl restart nginx
sudo systemctl enable nginx

On the first screen, create admin user and set site URL for your Wiki.

image-1024x628

Once you’ve filled required user details, click the “install” button.

image-1-1024x255

Wait for the installation to complete, this takes few seconds.

install-wikijs-centos-8-05

Once the installation is done, input email and password set during admin user creation.

image-2-1024x580

After successful login, you have an option of going to Admin panel or creating home page.

create-page-access-admin-wikijs-1024x565

 

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.