How to setup own selfhosted wiki

2021-02-02
#howto #ubuntu #server #selfhosted #docker #dokuwiki

Disclaimer: many links in this post are referral. If you are uncomfortable with it, just search for the text in the links and use results from the search engines.

§ Plan

  1. Spin up a new virtual server (1 CPU + 1 GB RAM is fairly enough) in Vultr, Digital Ocean, etc.
  2. Register a new domain name
  3. Install Docker and Docker Compose
  4. Use docker-compose to deploy a wiki
  5. Backups

§ Virtual server

For example, let it be Digital Ocean.

You need to create a 5$ basic droplet with Ubuntu 20.04 (Droplets -> Create droplet). Choose:

  1. Latest stable Ubuntu (in this time it is Ubuntu 20.04)
  2. Basic plan
  3. $5 size
  4. Any datacenter. Choose those that are closer to you.
  5. In additional settings check «IPv6» because it is cool 😎
  6. Authentication: SSH is must-have, generate key if needed

§ Domain name

One can register a domain name at the registrar of your choice. For Russian domains, I use reg.ru.

After registration (and some wait time, while DNS records are being updated across the world), add resource record in DNS editor: A for IPv4 and AAAA for IPv6. IPs you can find on the virtual machine info page.

More about resource records: https://en.wikipedia.org/wiki/List_of_DNS_record_types

§ Docker and docker-compose

For installation of Docker use the official doc:

# run as root
apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update && apt install docker-ce docker-ce-cli containerd.io

And install docker-compose by the official doc:

# run as root
curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

§ Deploy wiki

You need to choose wiki to install. Let it be Dokuwiki.

All you need is just a single docker-compose.yaml:

version: "3.4"
services:
  proxy:
    image: traefik:v2.0
    container_name: proxy
    restart: always
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.lech.acme.tlschallenge=true"
      - "--certificatesresolvers.lech.acme.email=blog@bikulov.org"
      - "--certificatesresolvers.lech.acme.storage=/letsencrypt/acme.json"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.https-redirect.entrypoints=web"
      - "traefik.http.routers.https-redirect.rule=HostRegexp(`{any:.*}`)"
      - "traefik.http.routers.https-redirect.middlewares=https-redirect"
      - "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https"
    ports:
      - "443:443"
      - "80:80"
    volumes:
      - proxy-data:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro
  
  dokuwiki:
    image: linuxserver/dokuwiki
    container_name: dokuwiki
    restart: always
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dokuwiki.rule=Host(`wiki.bikulov.org`)"
      - "traefik.http.routers.dokuwiki.entrypoints=websecure"
      - "traefik.http.routers.dokuwiki.tls.certresolver=lech"
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Moscow
    volumes:
      - dokuwiki-data:/config

volumes:
  proxy-data:
  dokuwiki-data:

You need to change:

  • certificatesresolvers.lech.acme.email to your email
  • traefik.http.routers.dokuwiki.rule to your host

There are two services proxy and dokuwiki with two data volumes. proxy knows about dokuwiki via labels. Only proxy exposes 80 and 443 ports to host machine and routes traffic to dokuwiki by matching rule Host(`wiki.bikulov.org`).

Just run in directory with yaml:

docker-compose up -d

More about docker-compose. More about data volumes. More about traefic.

§ Backups

More at backups can be fount in the official doc. Below I rovide the most essential: backup bash command.

Backup:

docker run --rm --volumes-from dokuwiki -v $(pwd):/backup ubuntu bash -c "tar cvfz /backup/dokuwiki_$(date +%s).tar.gz /config"

Restore:

docker run --rm --volumes-from dokuwiki -v $(pwd):/backup ubuntu bash -c "cd /config && rm -rf * && tar xvf /backup/backup.tar --strip 1"

So, the last building blog is to sync tars fom server elsewhere. You can achieve it with Syncthing, Yandex Disk, rclone and many others.