Install DokuWiki with Page Redirection

DokuWiki is a great tool to capture notes. There is no hassles of DB and all in this – All files are based on markdown and stored in server so backup is also easy.

Here are easy steps to install DokuWiki and also enable page redirection

Get the DokuWiki

wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz

Unzip and adjust permissions

sudo tar xf dokuwiki-stable.tgz
sudo chown -R www-data:www-data /var/www/dokuwiki

Most of the default config you see in Internet will give 404 error instead of creating a new page.


For my use case, I want to create a DokuWiki page automatically when I navigate to URL
Ex : www.notes.com/docker

If Docker page does not exist, below config of DokuWiki instead of giving 404, will allow you to create new page

Nginx Code

server {
    listen 80;
    server_name example.com www.example.com;
 
    #maximum file upload size is 4MB - change accordingly if needed
    client_max_body_size 4M;
    client_body_buffer_size 128k;
 
    root /var/www/dokuwiki;
    index doku.php;
 
    location / { try_files $uri $uri/ @dokuwiki; }
 
    location @dokuwiki {
        rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
        rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
        rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
        rewrite ^/(.*) /doku.php?id=$1&$args last;
    }
 
    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REDIRECT_STATUS 200;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    }
}

Posted

in

Tags: