How to install DokuWiki on Ubuntu

How to install DokuWiki on Ubuntu

Overview

  • DokuWiki is a historic open-source wiki engine first released in 2004. It operates based on PHP and functions without a database, using only the file system, making it lightweight and easy to manage for anyone. This article outlines the steps to install DokuWiki on an Ubuntu operating system.

Prerequisites

  • Your own internet domain
  • A remote server with Ubuntu operating system installed and accessible over the internet

Installing NGINX

  • NGINX enables the server to provide web services.
# Update packages to latest
$ sudo apt-get update && sudo apt-get upgrade -y

# Install NGINX
$ sudo apt-get install nginx -y
$ sudo systemctl enable nginx
$ sudo chmod -R 777 /var/www/html

# Start NGINX service
$ sudo systemctl start nginx

Installing PHP-FPM

  • PHP-FPM enables NGINX to execute PHP source code. Install it as follows:
# Install PHP-FPM package repository
$ sudo apt-get install ca-certificates apt-transport-https software-properties-common -y
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update

# Install PHP-FPM
$ sudo apt-get install php8.3-fpm php8.3-gd php8.3-xml -y 
$ sudo systemctl enable php8.3-fpm

# Start PHP-FPM service
$ sudo systemctl start php8.3-fpm

# Restart NGINX service
$ sudo systemctl restart nginx

Installing Certbot

  • Certbot automatically facilitates the installation of free SSL certificates from Let's Encrypt. Once installed, it will serve requests to your domain over HTTPS only.
### Install Certbot
$ sudo snap install core; sudo snap refresh core
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

### Automatically apply Certbot to NGINX
$ sudo certbot --nginx -d {your-domain}
$ sudo systemctl status snap.certbot.renew.service

NGINX Configuration

  • Add the following configuration for PHP-FPM and DokuWiki in the NGINX environment configuration file.
$ sudo nano /etc/nginx/sites-available/default
server {
    server_name {your-domain};

    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~ /(data|conf|bin|inc|vendor)/ {
        deny all;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/{your-domain}/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/{your-domain}/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    server_name {your-domain};

    if ($host = {your-domain}) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    return 404; # managed by Certbot
}

Firewall Configuration

  • On the remote server, allow only SSH and NGINX service ports through the firewall and start the service.
# Allow SSH and NGINX in firewall
$ sudo ufw allow ssh
$ sudo ufw allow 'Nginx Full'

# Start firewall service
$ sudo ufw enable
$ sudo ufw start

Installing DokuWiki

  • To install DokuWiki, navigate to download.dokuwiki.org in your browser, select the installation options that suit your preferences, and click the Download button to obtain the .tgz file URL. Use the acquired URL to install DokuWiki as follows:
# Install DokuWiki
$ cd /var/www/html
$ wget {your-dokuwiki-tgz-download-url}
$ tar xzvf {your-dokuwiki-tgz-filename}
$ sudo chown -R www-data:www-data /var/www/html/dokuwiki

# Deny crawling collection
$ nano /var/www/html/robots.txt
User-agent: *
Disallow: /
Disallow: /dokuwiki/
  • The installation process through the terminal console is now complete. To finish the installation, access https://{your-domain}/dokuwiki/install.php in your browser and follow the instructions.

References