How to install and configure the Wiki.js on CentOS 8 Cloud Servers

2021-08-01 By Aaron 15761 Views linux wiki.js cms_application
41 reviews

Wiki.js is a free and open-source wiki application built on Node.js. It uses Markdown files to save contents which can be saved directly to the Markdown file and synced with a Git repository.


Wiki.js offers features such as integrated access control, proper asset management as well as a built-in search engine.


This guide outlines the steps required to install Wiki.js on a CentOS8 Cloud server:

Requirements:

  • Updated CentOS8 server
  • Node.js, GIT and Redis
  • NGINX and MariaDB


Updating OS packages in server


  1. Log in to the server through SSH and execute the below command to update the OS packages.

    # dnf update -y
    

    wikijscentos1


Installing Node.js, GIT and Redis

Node.js needs to be installed in the server since Wiki.js is built on it.


  1. Before proceeding with the installation of Node.js, run the below command to install all required dependencies.

    # dnf install epel-release git curl unzip -y
    

    wikijscentos21

  2. Add the Node.js repository using the below command.

    # curl -sL https://rpm.nodesource.com/setup_12.x | bash -
    

    wikijscentos2

  3. Install Node.js and Redis by running the below commands.

    # dnf install nodejs redis -y
    

    wikijscentos3

  4. Start and enable the Redis service to start at system reboot

    # systemctl start redis
    
    # systemctl enable redis
    

    wikijscentos4


Installing NGINX and MariaDB

Wiki.js requires a web server as well as a database server to function.


  1. Run the below command to install the NGINX web server and MariaDB database server in the Cloud server.

    # dnf install nginx @mariadb -y
    

    wikijscentos5

  2. Start both the NGINX and MariaDB services and enable them to start up at system reboot.

    # systemctl start nginx
    
    # systemctl start mariadb
    
    # systemctl enable nginx
    
    # systemctl enable mariadb
    

    wikijscentos6

  3. Secure MariaDB installation by running the below command and completing the setup as below.

    # mysql_secure_installation
    


    Enter current password for root (enter for none):  
    Set root password? [Y/n] Y  
    New password:
    
    Re-enter new password:
    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
    

    wikijscentos7

    NOTE: Replace with the password that needs to be set as the MariaDB root password.

  4. Once the MariaDB database server is secured, it can be accessed by executing the below command.

    # mysql -u root -p
    


    Type in the root password set for the MariaDB server in the above step and then press Enter to access the database server command line.

    wikijscentos8

  5. Create a database and related database user that can be used for the installation of Wiki.js by executing the below commands in the MariaDB command prompt.


    In the context of this guide, the database name being used is lswikidb and lswikiuser is the associated database username.

    CREATE DATABASE lswikidb;
    GRANT ALL PRIVILEGES ON lswikidb.* TO 'lswikiuser'@'localhost' IDENTIFIED BY 'password';  
    FLUSH PRIVILEGES;  
    EXIT;
    

    wikijscentos9

    NOTE: Replace password in the above command with the actual password that needs to be set for the database user.


    Once all required services are installed in the server, the installation of Wiki.js can be proceeded with.


Installing Wiki.js


  1. Create a separate new user and group for the Wiki.js service. The user and group used in the context of this guide is wikijs.

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

    wikijscentos10

  2. Download the latest version of Wiki.js from the official website by executing the below command.

    # curl -s https://api.github.com/repos/Requarks/wiki/releases/latest | grep browser_download_url | grep -v windows | cut -d '"' -f 4 | wget -qi -
    

    wikijscentos11


    An archive named wiki-js.tar.gz will be downloaded after executing the above command.

  3. Create a folder for Wiki.js and then extract the contents of the downloaded archive file to the folder. In the context of this guide, the folder named lswiki is created under the path /var/www/html.

    # mkdir -p /var/www/html/lswiki
    
    # tar zxf wiki-js.tar.gz -C /var/www/html/lswiki
    

    wikijscentos12

  4. Switch to the folder lswiki and then make a copy of the sample config file config.sample.yml and rename it as config.yml.

    # cd /var/www/html/lswiki
    
    # cp config.sample.yml config.yml
    

    wikijscentos13

  5. Open the config.yml file using any editor of choice and update the database details with the details of the MariaDB database and database user that has been created, in the file in the below format.

    db:
    type: mariadb
    # PostgreSQL / MySQL / MariaDB / MS SQL Server only:
    host: localhost
    port: 3306
    user: lswikiuser
    pass: password
    db: lswikidb
    ssl: false
    


    Save and close the configuration file once the above details are typed in.

  6. Assign user permissions for the lswiki folder for the newly created user wikijs.

    # chown -R wikijs.wikijs /var/www/html/lswiki
    

    wikijscentos14

  7. Verify the Wiki.js installation by executing the below command.

    # node server
    


    If the installation is done smoothly, an output similar to below will be displayed when the above command is executed.

    wikijscentos15


Creating Systemd service file for Wiki.js

The next step in the configuration of Wiki.js is to create a systemd service file for it in order to manage the service. Follow the below steps for this.


  1. Create the systemd service file for Wiki.js under the /etc/systemd/system folder.

    # vi /etc/systemd/system/wiki.service
    
  2. Add the below entries in the newly created wiki.service systemd file.

    [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/html/lswiki
    [Install]
    WantedBy=multi-user.target
    

    NOTE: Replace User and WorkingDirectory values with the actual configured settings.


    Save and close the systemd service file once the above details are typed in.

  3. Reload the systemd daemon, and then start and enable the wiki service to start at system reboot by executing the below commands.

    # systemctl daemon-reload
    
    # systemctl start wiki
    
    # systemctl enable wiki
    

    wikijscentos16


Configuring NGINX as Reverse Proxy

NGINX web service needs to be configured as a reverse proxy in order to access Wiki.js on port 80 of the Cloud server.


  1. Create a new NGINX virtual host configuration file for the Wiki.js service using the below command.

    # vi /etc/nginx/conf.d/wikijs.conf
    
  2. Add the below entries in the configuration file, save the file and then close the file.

    server {
    listen  80;
    server_name wiki.layerstack.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;
    }
    }
    

    NOTE: Replace wiki.layerstack.com with the actual domain name under which Wiki.js needs to be installed. The domain name should also correctly resolve to the Cloud server IP address.

  3. Restart NGINX services in-order to apply the changes.

    # systemctl restart nginx
    

    wikijscentos17


Accessing Wiki.js


  1. The installed Wiki.js service can now be accessed through a browser by using the website name configured in the NGINX configuration file.


    In this guide’s context, the URL is as provided below:

    http://wiki.layerstack.com*
    


    The URL will be redirected to a page similar to below. Type in the administrator email address, admin password (twice), the site URL and then click on Install button:

    wikijscentos18

  2. Once the installation is completed, the page will be redirected to the Wiki.js login page as below. Provide the administrator email address and password set in the above step to log in.

    wikijscentos19

  3. Once logged in, the Wiki.js dashboard will be displayed as below, from where the service can be managed further and made use of to create wiki pages.

    wikijscentos20


Related Tutorials

What do you think about this article?

Rate this article
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.