Installing Wiki.js on Ubuntu 20.04, with Postgresql

This probably won’t make sense to anyone else, but these are my notes related to installing Wiki.js and Postgresql on an Ubuntu 20.04 system. Everything here is related to setting up a new Ubuntu system and then running Wiki.js:

New Linode Server (Ubuntu 20)
=============================
sudo adduser fred
sudo usermod -aG sudo fred

## Install Postgres
-------------------
- https://www.linode.com/docs/guides/how-to-install-use-postgresql-ubuntu-20-04/
- https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-20-04

- change the 'postgres' user account password:
    passwd postgres (then supply the password)

- Change the password for the postgres PostgreSQL user to use when connecting over a network.
    psql -c "ALTER USER postgres WITH PASSWORD 'the_password'"

- /etc/postgresql/12/main/pg_hba.conf

## Install Node.js
------------------
- https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04
    apt install nodejs
    nodejs -v
        v10.19.0

## Connect Postgres & Wiki.js
-----------------------------
- become root
- become postgres user:
    sudo -i -u postgres
- create a new user:
    createuser --interactive
    # does not let you set the password here
    
    # this might work:
    psql -c "ALTER USER db_user WITH PASSWORD 'the_password'"
    
- create the database
    createdb wiki_js

  # PostgreSQL / MySQL / MariaDB / MS SQL Server only:
  host: localhost
  port: 5432
  user: bd_user
  pass: db_password
  db:   db_name
  ssl:  false

PostgreSQL Backup
-----------------
pg_dump -h localhost -U db_user -W db_name > db.dump


How to use a Different SSH Port on the Server
---------------------------------------------
vi /etc/ssh/sshd_config
systemctl restart ssh
netstat -tlpn| grep ssh
ss -tlpn| grep ssh

ufw allow 5150/tcp
ufw status verbose


## NGINX
========

## htpasswd with NGINX
----------------------
- https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
- https://www.interserver.net/tips/kb/apache-htpasswd-authentication-ubuntu/
    apt-get install apache2-utils
    # use any directory, as desired:
    touch /etc/nginx/.htpasswd
    htpasswd -c /etc/nginx/.htpasswd the_username
    the_password

## Wiki.js Setup
----------------
- the wiki is now available at example.com
- wiki admin email: foo
- wiki admin pass:  bar

wiki.js version
    download/2.5.201/wiki-js.tar.gz
nodejs -v
    v10.19.0
psql -version
    psql (12.7 (Ubuntu 12.7-0ubuntu0.20.04.1))

OS: Ubuntu 20.04
Wiki.js version: 2.5.201
Database engine: PostgreSQL 12+214


/etc/systemd/system/wiki.service (how to create a simple Ubuntu service)
================================
[Unit]
Description=Wiki.js
After=network.target

[Service]
Type=simple
# Wiki.js runs with the 'node server' command
ExecStart=/usr/bin/node server
Restart=always
# Consider creating a dedicated user for Wiki.js here:
User=nobody
Environment=NODE_ENV=production
WorkingDirectory=/var/www/foobar.baz/wiki.js

[Install]
WantedBy=multi-user.target

Reload systemd:
    systemctl daemon-reload

Run the service:
    systemctl start wiki

Enable the service on system boot.
    systemctl enable wiki

Note: You can see the logs of the service using journalctl -u wiki

Again, all of those commands are related to setting up a new Ubuntu system and then running Wiki.js on that server. They recommend using Postgres, and I used to love using Postgres, so I went with it.