User Tools

Site Tools


servers:nginx:dokuwiki

Information

Prerequisites

Download Source

sudo git clone --branch 'master' --depth '1' --recurse-submodules 'https://github.com/splitbrain/dokuwiki.git' '/var/www/wiki' && sudo chown -R 'www-data':'www-data' '/var/www/wiki' && sync

nginx + PHP-FPM Configuration

PHP-FPM Socket

sudo -e '/etc/php/7.2/fpm/pool.d/wiki.conf' && sudo systemctl restart 'php7.2-fpm'
[wiki]
user = www-data
group = www-data

listen = /run/php/wiki.sock
listen.owner = www-data
listen.group = www-data
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 8
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4

php_value[date.timezone] = "America/New_York"
php_value[upload_tmp_dir] = "/tmp"

php_value[max_execution_time] = "200"
php_value[memory_limit] = "512M"
php_value[post_max_size] = "10M"
php_value[upload_max_filesize] = "10M"
php_value[max_file_uploads] = "100"

php_value[session.save_handler] = "files"
php_value[session.save_path] = "/var/lib/php/session"
php_value[soap.wsdl_cache_dir] = "/var/lib/php/wsdlcache"
php_value[opcache.file_cache] = "/var/lib/php/opcache"

FastCGI

sudo -e '/etc/nginx/snippets/wiki.conf'
# PHP-FPM
location ~ \.(php|phar)(/.*)?$ {
    fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;

    fastcgi_intercept_errors on;
    fastcgi_index doku.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/run/php/wiki.sock;
}

Server Block

sudo -e '/etc/nginx/sites-available/wiki.conf'
server {
    listen '443' 'ssl' 'http2';
    server_name 'wiki.realmofespionage.xyz';
    root '/var/www/wiki';
    index 'doku.php';

    include '/etc/nginx/snippets/wiki.conf';
    include '/etc/nginx/snippets/headers.conf';

    client_max_body_size '10M';

    add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" always;

#    access_log  /var/log/nginx/wiki-access.log;
#    error_log  /var/log/nginx/wiki-error.log;

#    location = /install.php {
#        deny all;
#    }

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

#    location ~ /data/ {
#        internal;
#    }

    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;
    }
}

Enable

sudo rm -f '/etc/nginx/sites-enabled/wiki.conf' && sudo ln -s '/etc/nginx/sites-available/wiki.conf' '/etc/nginx/sites-enabled/wiki.conf' && sudo systemctl reload 'nginx' && sync

Initial Setup

Settings

Template Style Settings

  • Alternative background color: #484848
  • The general link color: #3d8bff
  • :!: The width of the full site: 100em 4)

nginx Server Block Deny Directives

  • Uncomment commented sections (except logs)
  • Do after initial setup
sudo -e '/etc/nginx/sites-available/wiki.conf' && sudo systemctl reload 'nginx'

URL Rewrite

  • Admin → Configuration Settings
  • Set Use nice URLs to .htaccess

Double-hyphen Convert Disable

  • This prevents -- from becoming a – (long hyphen), which breaks some command's syntax
echo '--      --' | sudo tee '/var/www/wiki/conf/entities.local.conf' > '/dev/null' && sudo chown 'www-data':'www-data' '/var/www/wiki/conf/entities.local.conf'

Services

Updater

Service

sudo -e '/etc/systemd/system/wiki-up.service'
[Service]
User=www-data
Group=www-data
Type=oneshot
ExecStart='/usr/bin/git' -C '/var/www/wiki' pull origin 'master'
ExecStartPost='/bin/sync'

Timer

  • Every day at 01:00:00
sudo -e '/etc/systemd/system/wiki-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'wiki-up.timer' --now && sudo systemctl start 'wiki-up' && sudo systemctl status 'wiki-up' -l
[Unit]
Description=DokuWiki Git Updater
After=network-online.target
Wants=network-online.target

[Timer]
OnCalendar=*-*-* 01:00:00
Persistent=true

[Install]
WantedBy=timers.target

Maintenance

Service

  • :!: The commented ExecStart would remove page edits older than 90 days
sudo -e '/etc/systemd/system/wiki-m.service'
[Service]
User=www-data
Group=www-data
Type=oneshot
WorkingDirectory=/var/www/wiki
ExecStart='/usr/bin/git' -C '/var/www/wiki' gc --aggressive --prune='all'
ExecStart='/usr/bin/git' -C '/var/www/wiki' fsck --full --strict
#ExecStart='/bin/bash' -c "find '/var/www/wiki/data'/{attic,cache,locks,media_attic}/ -type 'f' -mtime +'90' -delete"
ExecStart='/bin/bash' -c "find '/var/www/wiki/data'/{attic,cache,index,locks,media,media_attic,media_meta,meta,pages,tmp}/ -mindepth '1' -type 'd' -empty -delete"
ExecStart='/usr/bin/php' '/var/www/wiki/bin/indexer.php' --clear
ExecStartPost='/bin/sync'

Timer

  • 01 day of every month at 01:20:00
sudo -e '/etc/systemd/system/wiki-m.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'wiki-m.timer' --now
[Unit]
Description=DokuWiki Maintenance

[Timer]
OnCalendar=*-*-01 01:20:00
Persistent=true

[Install]
WantedBy=timers.target

Backup

  • This backs up an archive to the local disk and to a NAS

Service

mkdir -p ~/'backups' && sudo -e '/etc/systemd/system/wiki-fb.service' && sudo sed -i 's/CHANGEME/'$USER'/g' '/etc/systemd/system/wiki-fb.service'
[Service]
Type=oneshot
WorkingDirectory=/var/www/wiki
ExecStart='/bin/bash' -c '"/bin/tar" -cvzf "/home/CHANGEME/backups/dokuwiki-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" "data/pages" "data/meta" "data/media" "data/media_meta" "data/attic" "data/media_attic" "conf"'
ExecStartPost='/bin/sync'

Timer

  • Every day at 01:50:00
sudo -e '/etc/systemd/system/wiki-fb.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'wiki-fb.timer' --now && sudo systemctl start 'wiki-fb' && sudo systemctl status 'wiki-fb' -l
[Unit]
Description=DokuWiki Files Backup

[Timer]
OnCalendar=*-*-* 01:50:00
Persistent=true

[Install]
WantedBy=timers.target

Backup

  • Create backup archive on server and transfer to client computer

Server

Archive Folders

cd '/var/www/wiki' && sudo tar -cvzf ~/'dokuwiki-files-manual-'$(date +%Y-%m-%d)'.tar.gz' 'data/pages' 'data/meta' 'data/media' 'data/media_meta' 'data/attic' 'data/media_attic' 'conf' && cd ~ && sync

Client

Transfer Archive to Client

scp espionage724@192.168.1.153:~/'dokuwiki-files-'*'.tar.gz' ~/'Downloads' && sync

Restore

Client

Transfer Archive to Server

scp ~/'Downloads/dokuwiki-files-'*'.tar.gz' espionage724@192.168.1.153:~

Remove Archive

rm ~/'Downloads/dokuwiki-files-'*'.tar.gz' && sync

Server

Stop nginx

sudo systemctl stop 'nginx'

Remove Previous Folders

ls ~/'dokuwiki-files-'*'.tar.gz' && sudo rm -Rf '/var/www/wiki/data/pages' '/var/www/wiki/data/meta' '/var/www/wiki/data/media' '/var/www/wiki/data/media_meta' '/var/www/wiki/data/attic' '/var/www/wiki/data/media_attic' '/var/www/wiki/conf'

Restore Folders

cd '/var/www/wiki' && sudo tar -xvzf ~/'dokuwiki-files-'*'.tar.gz' 'data/pages' 'data/meta' 'data/media' 'data/media_meta' 'data/attic' 'data/media_attic' 'conf' && sudo chown -R 'www-data':'www-data' '/var/www/wiki' && cd ~ && sync

Start nginx

sudo systemctl start 'nginx'

Remove Archive

  • Verify that DokuWiki works before running
rm -R ~/'dokuwiki-files-'*'.tar.gz' && sync
3)
you are here :p
4)
this caused some kind of scrollbar I believe on a 1280×800 laptop
servers/nginx/dokuwiki.txt · Last modified: 2019/10/24 14:21 by Sean Rhone