# Wiki.js Setup

<div style="text-align: right">Antoine de Barbarin</div>

---

## Install *nodejs*

Enable **nodejs v22** in the **dnf** repository:
```bash
dnf module enable nodejs:22
```
The result should be like that (type `y` when asked for confirmation):
```bash
Last metadata expiration check: 2:29:44 ago on Sun 01 Jun 2025 07:37:42 AM UTC.
Dependencies resolved.
==================================================================================================================
 Package                    Architecture              Version                    Repository                  Size
==================================================================================================================
Enabling module streams:
 nodejs                                               22

Transaction Summary
==================================================================================================================

Is this ok [y/N]: y
Complete!
```

Install nodejs and npm
```bash
dnf install -y nodejs npm
```


## Wiki.js Installation

Download the latest version of Wiki.js:

```bash
wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz
```

Extract the package to a new folder `/srv/wikijs`:

```bash
mkdir /srv/wikijs
tar xzf wiki-js.tar.gz -C /srv/wikijs
cd /srv/wikijs
```

Rename the sample config file to `config.yml`:

```bash
mv config.sample.yml config.yml
```

Edit the config file and fill in your database and port settings (host: `172.17.0.6`, port: `5432`, user: `wikijs`, database: `wikijs`) and set `ha`to true:

```bash
vim config.yml
```

On the **PostgreSQL** Server, give access to the user `wikijs` on the database `wikijs` from both web servers.
Add the following text in the file `/var/lib/pgsql/17/data/pg_hba.conf`

```
host    wikijs          wikijs          172.16.0.2/32            scram-sha-256
host    wikijs          wikijs          172.16.0.3/32            scram-sha-256
```

Back to our webserver, run Wiki.js with the command

```bash
node server
```

![image-20250601121248319](https://docs.adebarbarin.com/uploads/images/gallery/2025-06/wikijs-01.png)

Open the browser with the **URL** `http://172.16.0.2:3000/` and fill the form

![image-20250601121540857](https://docs.adebarbarin.com/uploads/images/gallery/2025-06/wikijs-02.png)

When the installation is complete, you will be redirected to the login page. The setup is complete, you can log in with the administrator account.

![image-20250601122843218](https://docs.adebarbarin.com/uploads/images/gallery/2025-06/wikijs-03.png)

![image-20250601122914711](https://docs.adebarbarin.com/uploads/images/gallery/2025-06/wikijs-04.png)

## Run as service

Create a new system user to run wikijs and give complete ownership of `/srv/wikijs` to it

```bash
useradd -r wikijs -s /bin/false -d /srv/wikijs
chown -R wikijs:wikijs /srv/wikijs
```

Running the command `cat /etc/passwd | grep wikijs`, you should see something similar

```bash
wikijs:x:998:995::/srv/wikijs:/bin/false
```

And running `ll /srv & ll /srv/wikijs`, you should also see

```bash
total 4
drwxr-xr-x 6 wikijs wikijs 4096 Jun  1 09:56 wikijs
total 104
drwxr-xr-x   8 wikijs wikijs  4096 Mar 24 01:36 assets
-rw-r--r--   1 wikijs wikijs  4974 Jun  1 09:56 config.yml
drwxr-xr-x   5 wikijs wikijs  4096 Jun  1 10:26 data
-rw-r--r--   1 wikijs wikijs 34520 Mar 24 01:33 LICENSE
drwxr-xr-x 953 wikijs wikijs 36864 Mar 24 01:37 node_modules
-rw-r--r--   1 wikijs wikijs 12267 Mar 24 01:33 package.json
drwxr-xr-x  17 wikijs wikijs  4096 Mar 24 01:33 server
```

Create a new file named `wikijs.service` inside directory `/etc/systemd/system`.

```bash
vim /etc/systemd/system/wikijs.service
```

Paste the following contents (assuming your wiki is installed at `/var/wiki`):

```ini
[Unit]
Description=Wiki.js
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always
User=wikijs
Environment=NODE_ENV=production
WorkingDirectory=/srv/wikijs

[Install]
WantedBy=multi-user.target
```

Reload **systemd**:

```bash
systemctl daemon-reload
```

Run the service:

```bash
systemctl start wikijs
```

Enable the service on system boot.

```bash
systemctl enable wikijs
```