Using a Different System?
-
How to Install Wiki.js on Ubuntu 18.04
-
How to Install Wiki.js on CentOS 7
-
How to Install Wiki.js on Fedora 28
-
How to Install Wiki.js on FreeBSD 11
Wiki.js is a free and open source, modern wiki app built on Node.js, MongoDB, Git and Markdown. Wiki.js source code is publicly hosted on GitHub. This guide will show you how to install Wiki.js on a fresh Debian 9 Vultr instance by using Node.js, MongoDB, PM2, Nginx, Git and Acme.sh.
Requirements
- Node.js 6.9.0 or later
- MongoDB 3.2 or later
- Nginx
- Git 2.7.4 or later
- A Git-compliant repository (public or private) (optional)
- Minimum of
768MB RAM
- Domain name with
A
/AAAA
records set up
Check the Debian version.
lsb_release -ds
# Debian GNU/Linux 9.4 (stretch)
Ensure that your system is up to date.
apt update && apt upgrade -y
Install necessary packages.
apt install -y build-essential apt-transport-https sudo curl wget dirmngr sudo
Create a new non-root
user account with sudo
access and switch to it.
adduser johndoe --gecos "John Doe"
usermod -aG sudo johndoe
su - johndoe
NOTE: Replace johndoe
with your username.
Set up the timezone.
sudo dpkg-reconfigure tzdata
Install Git
Install Git on Debian.
sudo apt install -y git
Verify the Git version.
git --version
# git version 2.11.0
Install Node.js
Install Node.js by utilizing NodeSource APT repository for Node.js.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt install -y nodejs
Check the Node.js and npm versions.
node -v && npm -v
# v8.11.2
# 5.6.0
Install MongoDB
Wiki.js uses MongoDB as a database engine. According to that, we will need to install MongoDB on our server. We will use the official MongoDB repositories for installation.
Install MongoDB Community Edition.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt update
sudo apt install -y mongodb-org
Check the version.
mongo --version | head -n 1 && mongod --version | head -n 1
# MongoDB shell version v3.6.5
# db version v3.6.5
Enable and start MongoDB.
sudo systemctl enable mongod.service
sudo systemctl start mongod.service
Install and configure Nginx
It is highly recommended to put a standard web server in front of Wiki.js. This ensures you can use features like SSL, multiple websites, caching and more. We will use Nginx in this tutorial, but any other server will do, you just need to configure it properly.
Install Nginx.
wget https://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
rm nginx_signing.key
sudo -s
printf "deb https://nginx.org/packages/mainline/debian/ $(lsb_release -sc) nginx/ndeb-src https://nginx.org/packages/mainline/debian/ $(lsb_release -sc) nginx/n" >> /etc/apt/sources.list.d/nginx_mainline.list
exit
sudo apt update
sudo apt install -y nginx
Check the version.
sudo nginx -v
# nginx version: nginx/1.15.0
Enable and start Nginx.
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
Configure Nginx as an HTTP
or HTTPS
(if you use SSL) reverse proxy for Wiki.js application.
Run sudo vim /etc/nginx/conf.d/wiki.js.conf
and populate it with the basic reverse proxy configuration below.
server {
listen [::]:80;
listen 80;
server_name wiki.example.com;
root /usr/share/nginx/html;
charset utf-8;
client_max_body_size 50M;
location /.well-known/acme-challenge/ {
allow all;
}
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;
}
}
The only things you need to change in the above config is the server_name
directive, and potentially the proxy_pass
directive if you decide to configure some other port than 3000
. Wiki.js uses port 3000
by default.
Check the configuration.
sudo nginx -t
Reload Nginx.
sudo systemctl reload nginx.service
Install Acme.sh and obtain a Let’s Encrypt certificate (optional)
Securing your wiki with HTTPS
is not necessary, but it is a good practice to secure your site traffic. In order to obtain an SSL certificate from Let’s Encrypt we will use the Acme.sh client. Acme.sh is a pure unix shell software for obtaining SSL certificates from Let’s Encrypt with zero dependencies. That makes it very lightweight in comparison to some other ACME protocol clients that require a lot of dependencies to run successfully.
Download and install Acme.sh.
sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail your_email@example.com
cd ~
Check the version.
/etc/letsencrypt/acme.sh --version
# v2.7.9
Obtain RSA and ECDSA certificates for wiki.example.com
.
# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt -d wiki.example.com --webroot /usr/share/nginx/html --reloadcmd "sudo systemctl reload nginx.service" --accountemail your_email@example.com --ocsp-must-staple --keylength 2048
# ECDSA/ECC P-256
sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt -d wiki.example.com --webroot /usr/share/nginx/html --reloadcmd "sudo systemctl reload nginx.service" --accountemail your_email@example.com --ocsp-must-staple --keylength ec-256
NOTE: Don’t forget to replace wiki.example.com
with your domain name.
After running the above commands, your certificates and keys will be in the following directories.
- For RSA:
/etc/letsencrypt/wiki.example.com
directory. - For ECC/ECDSA:
/etc/letsencrypt/wiki.example.com_ecc
directory.
After obtaining certificates from Let’s Encrypt, we need to configure Nginx to take advantage of them.
Run sudo vim /etc/nginx/conf.d/wiki.js.conf
again and configure Nginx as an HTTPS
reverse proxy.
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
listen [::]:80;
listen 80;
server_name wiki.example.com;
root /usr/share/nginx/html;
charset utf-8;
client_max_body_size 50M;
location /.well-known/acme-challenge/ {
allow all;
}
# RSA
ssl_certificate /etc/letsencrypt/wiki.example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/wiki.example.com/example.com.key;
# ECDSA
ssl_certificate /etc/letsencrypt/wiki.example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/wiki.example.com_ecc/example.com.key;
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;
}
}
Check the configuration.
sudo nginx -t
Reload Nginx.
sudo systemctl reload nginx.service
Install Wiki.js
Create an empty document root folder where Wiki.js should be installed.
sudo mkdir -p /var/www/wiki.example.com
Navigate to the document root folder.
cd /var/www/wiki.example.com
Change ownership of /var/www/wiki.example.com
folder to user johndoe
.
sudo chown -R johndoe:johndoe /var/www/wiki.example.com
From the /var/www/wiki.example.com
folder, run the following command to download and install Wiki.js.
curl -sSo- https://wiki.js.org/install.sh | bash
You can run the following command in order to view the currently installed version of Wiki.js.
node wiki --version
# 1.0.78
Once the installation is completed, you’ll be prompted to run the configuration wizard.
Start the configuration wizard by running.
node wiki configure
This will notify you to navigate to http://localhost:3000
to configure Wiki.js. If you have Nginx in front of Wiki.js, then it means you can open your domain name (e.g. http://wiki.example.com
) instead of going to localhost
.
Using your web browser, navigate to http://wiki.example.com
and follow the on-screen instructions. All the settings entered during the configuration wizard are saved in the config.yml
file. The configuration wizard will automatically start Wiki.js for you.
Setup PM2
By default, Wiki.js will not start automatically after a system reboot. In order to make it start on boot, we need to setup the PM2 process manager. PM2 comes bundled with Wiki.js as a local NPM module, so we don’t need to install PM2 globally.
Tell PM2 to configure itself as a startup service.
/var/www/wiki.example.com/node_modules/pm2/bin/pm2 startup
Finally, save the current PM2 configuration.
/var/www/wiki.example.com/node_modules/pm2/bin/pm2 save
Your Wiki.js instance runs as a background process, using PM2 as its process manager. You can reboot your OS with sudo reboot
and check if Wiki.js starts after a reboot.
Want to contribute?
You could earn up to $300 by adding new articles
Suggest an update
Request an article