Wiki.js is a robust and versatile wiki platform that is both free and open-source. Built on Node.js, Git, and Markdown, it is designed to conserve system resources while delivering high performance. Distributed under the AGPL-v3 License, Wiki.js offers flexibility across various environments, from local operating systems to cloud solutions like Heroku, and container technologies such as Docker and Kubernetes.
Compatible with PostgreSQL, Wiki.js boasts over 50 integrations that enhance functionalities like authentication, logging, search, rendering, and storage. This highly customizable software is ideal for documenting your technology stack with its intuitive administration dashboard and interface.
This guide walks you through the installation and configuration of Wiki.js on an Ubuntu 22.04 server. Using PostgreSQL as the database and Apache2 as a reverse proxy, you will also set up a secure HTTPS/SSL connection for your installation. By the end, you will have a fully functional and secure Wiki.js setup on your Ubuntu system.
Prerequisites
To proceed with this installation, ensure you have the following:
- An Ubuntu 22.04 server.
- A non-root user with root/administrator privileges.
- A domain name directed to your Ubuntu server’s IP address.
Installing Node.js
Before proceeding with the Wiki.js installation, you need to set up the necessary dependencies. Since Wiki.js is primarily written in JavaScript, you’ll first install the Node.js runtime. Although available in the default Ubuntu repository, this guide recommends using the Nodesource repository for the LTS version of Node.js v16.
Execute the following curl command to add the Nodesource repository to your system:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
Install Node.js using:
sudo apt install nodejs
Verify the installation by checking the version:
node --version npm --version
Installing PostgreSQL Database
While Wiki.js supports databases like MySQL/MariaDB and SQLite, PostgreSQL is recommended for production environments. Install PostgreSQL as follows:
sudo apt install postgresql postgresql-common
After the installation, check the PostgreSQL service status:
sudo systemctl is-enabled postgresql sudo systemctl status postgresql
To create a PostgreSQL database and user for Wiki.js, log in to the PostgreSQL console:
sudo -u postgres psql
Create a new database and user:
CREATE DATABASE wikijs; CREATE USER wiki WITH ENCRYPTED PASSWORD 'wikijspassword'; GRANT ALL PRIVILEGES ON DATABASE wikijs TO wiki;
To exit, press Ctrl+D or type \q.
Installing Wiki.js
Follow these steps to manually install Wiki.js on your system. This involves creating a system user, downloading Wiki.js, setting it up with PostgreSQL, and running it as a systemd service.
Create a system user for Wiki.js:
sudo useradd -r -d /opt/wikijs -s /usr/sbin/nologin wiki
Download Wiki.js source:
wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz
Create a directory and extract the source code:
mkdir -p /opt/wikijs tar xzf wiki-js.tar.gz -C /opt/wikijs
Edit the configuration file:
cp /opt/wikijs/config.sample.yml /opt/wikijs/config.yml nano /opt/wikijs/config.yml
Modify the following configurations in the ‘config.yml’ file:
# default port wikijs will run port: 3000 # PostgreSQL database details db: type: postgres host: localhost port: 5432 user: wiki pass: wikijspassword db: wikijs ssl: false # bind wikijs to localhost only bindIP: 127.0.0.1 # setup log and the format loglevel: info logFormat: json
Save the file and assign ownership of the directory to the new user:
sudo chown -R wiki:wiki /opt/wikijs
Create a systemd service file for Wiki.js:
sudo nano /etc/systemd/system/wikijs.service
Add the following configuration:
[Unit] Description=Wiki.js After=network.target postgresql.service [Service] Type=simple ExecStart=/usr/bin/node server Restart=always User=wiki Environment=NODE_ENV=production WorkingDirectory=/opt/wikijs [Install] WantedBy=multi-user.target
Save the file, reload the system manager, and start the service:
sudo systemctl daemon-reload sudo systemctl start wikijs sudo systemctl enable wikijs
Verify the service status:
sudo systemctl status wikijs
Setting up Apache2 as Reverse Proxy
To expose Wiki.js running on port 3000 to external networks, set up Apache2 as a reverse proxy with SSL:
sudo apt install apache2
Open HTTP and HTTPS ports:
sudo ufw allow "Apache Full" sudo ufw status
Enable necessary Apache2 modules:
sudo a2enmod proxy proxy_http ssl remoteip http2
Create a virtual host configuration:
sudo nano /etc/apache2/sites-available/wikijs.conf
Use your domain name and SSL path:
<VirtualHost *:80> ServerName wiki.howtoforge.local # Comment to prevent HTTP to HTTPS redirect Redirect permanent / https://wiki.howtoforge.local ErrorLog /var/log/apache2/wiki.howtoforge.local-error.log CustomLog /var/log/apache2/wiki.howtoforge.local-access.log combined </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName wiki.howtoforge.local ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3000/" ProxyPassReverse "/" "http://127.0.0.1:3000/" SSLEngine on SSLCertificateFile /etc/letsencrypt/live/wiki.howtoforge.local/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/wiki.howtoforge.local/privkey.pem Protocols h2 http/1.1 # Enable only strong encryption ciphers and prefer versions with forwarding Secrecy SSLCipherSuite HIGH:RC4-SHA:AES128-SHA:!aNULL:!MD5 SSLHonorCipherOrder on # Disable insecure SSL and TLS versions SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 ErrorLog /var/log/apache2/wiki.howtoforge.local-error.log CustomLog /var/log/apache2/wiki.howtoforge.local-access.log combined </VirtualHost> </IfModule>
Enable the site and restart Apache2:
sudo a2ensite wikijs.conf sudo apachectl configtest sudo systemctl restart apache2
Configuring Wiki.js Installation
Go to your Wiki.js domain (e.g., https://wiki.howtoforge.local/). Fill in your admin email, password, and site URL to start the installation.
Once installed, log in using your admin credentials, and you will be directed to create a homepage for Wiki.js.
Create a homepage using Markdown or another preferred editor. Enter title, description, and save it as the default index page.
Your Wiki.js home page is now set up:
Access the administration dashboard by clicking the gear icon on the top left:
Conclusion
You have successfully completed the setup of Wiki.js on an Ubuntu 22.04 server using PostgreSQL and Apache2 as a reverse proxy. Your installation is secured with UFW and SSL/HTTPS. Explore further by creating additional content, setting up categories, adding modules for enhanced functionality, or applying new themes.
FAQ
- Can I use a database other than PostgreSQL?
Yes, Wiki.js supports MySQL/MariaDB and SQLite, although PostgreSQL is recommended for production environments. - How do I troubleshoot if Wiki.js doesn’t start?
Check the service status withsudo systemctl status wikijs
and review the logs in/var/log/syslog
to identify any issues. - Is it mandatory to use Apache as a reverse proxy?
No, you can use other web servers like Nginx for reverse proxy with similar configurations for SSL and proxy settings. - Can I customize the appearance of Wiki.js?
Yes, you can apply different themes and extensions to customize the look and feel of your Wiki.js instance. - What if I need to upgrade Node.js?
Follow the Nodesource repository for guidance on upgrading Node.js, replacing the existing one with the latest supported version for Wiki.js.