servers:windows:nginx:dokuwiki
Table of Contents
Information
Prerequisites
TODO
Dependencies
Git
- Last tested:
Git-2.46.0-64-bit.exe
- Git from the command line and also from 3rd-party software
Download Source
git clone --branch "master" --depth "1" --recurse-submodules "https://github.com/splitbrain/dokuwiki.git" "C:\www\wiki"
explorer "C:\www\wiki"
Environment
PHP
notepad "%SystemDrive%\www\php\wiki-php.ini"
[PHP] extension_dir = ".\ext" extension="bz2" extension="gd" extension="intl" extension="mbstring" extension="openssl" [Date] date.timezone = "America/New_York"
nginx + PHP-CGI Configuration
PHP-CGI
notepad "%SystemDrive%\www\nginx-default.d\wiki.conf"
# PHP-CGI location ~ \.(php)(/.*)?$ { fastcgi_split_path_info ^(.+\.(?:php))(/.*)$; 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_param "HTTPS" "on"; fastcgi_pass "127.0.0.1:9002"; }
Process
notepad "%UserProfile%\Desktop\Wiki php-cgi.bat"
CD "%SystemDrive%\php-"*"-nts-Win32-vs16-x64\" SET PHP_FCGI_MAX_REQUESTS="0" SET PHP_FCGI_CHILDREN="1" START "Wiki PHP-CGI" "php-cgi.exe" -b "127.0.0.1:9002" -c "%SystemDrive%\www\php\wiki-php.ini"
Server Block
notepad "%SystemDrive%\www\nginx-vhosts.d\wiki.conf"
server { listen "443" "ssl"; http2 "on"; server_name "wiki.realmofespionage.xyz"; root "C:/www/wiki"; index "doku.php"; include C:/www/nginx-default.d/wiki.conf; include C:/www/nginx-default.d/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 logs/wiki-access.log; # error_log logs/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; } }
"%UserProfile%\Desktop\nginx Reload.bat"
Initial Setup
Settings
Plugins
Template Style Settings
- Alternative background color:
#484848
(dark gray) - The general link color:
#3d8bff
(blue) - Width of full site:
85%
- Width of sidebar:
25%
nginx Server Block Deny Directives
- Uncomment commented sections (except logs)
- Do after initial setup
notepad "%SystemDrive%\www\nginx-vhosts.d\wiki.conf"
"%UserProfile%\Desktop\nginx Reload.bat"
URL Rewrite
- Admin → Configuration Settings → DokuWiki → Advanced → userewrite
.htaccess
Double-hyphen Convert Disable
- This prevents -- from becoming a – (long hyphen), which breaks some command's syntax
notepad "%SystemDrive%\www\wiki\conf\entities.local.conf"
-- --
Services
- TODO
Updater
Service
- 2023/09/12: TODO: SELinux prevents various actions with
npm
; is it even needed?
sudo -e '/etc/systemd/system/main-up.service'
[Service] User=nginx Group=nginx Type=oneshot WorkingDirectory=/var/www/main Environment="COMPOSER_CACHE_DIR=/dev/null" ExecStart='/usr/bin/git' -C '/var/www/main' pull origin '5.1-dev' ExecStart='/usr/bin/composer' install #ExecStart='/usr/bin/npm' ci --logs-max='0' #ExecStart='/usr/bin/npm' audit fix --audit-level='none' --logs-max='0' ExecStartPost='/usr/bin/sync'
Timer
- Every day at
02:00:00
sudo -e '/etc/systemd/system/main-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'main-up.timer' --now
[Unit] Description=Joomla Git Updater After=network-online.target Wants=network-online.target [Timer] OnCalendar=*-*-* 02:00:00 Persistent=true [Install] WantedBy=timers.target
Maintenance
Service
sudo -e '/etc/systemd/system/main-m.service'
[Service] User=nginx Group=nginx Type=oneshot ExecStart='/usr/bin/git' -C '/var/www/main' gc --aggressive --prune='all' ExecStart='/usr/bin/git' -C '/var/www/main' fsck --full --strict ExecStartPost='/usr/bin/sync'
Timer
01
day of every month at02:20:00
sudo -e '/etc/systemd/system/main-m.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'main-m.timer' --now
[Unit] Description=Joomla Maintenance After=network-online.target Wants=network-online.target [Timer] OnCalendar=*-*-01 02:20:00 Persistent=true [Install] WantedBy=timers.target
Backup
Files
Service
mkdir -p ~/'backups' && sudo -e '/etc/systemd/system/main-fb.service' && sudo sed -i 's/CHANGEME/'$USER'/g' '/etc/systemd/system/main-fb.service'
[Service] Type=oneshot WorkingDirectory=/var/www ExecStart='/usr/bin/bash' -c '"/usr/bin/tar" -czf "/home/CHANGEME/backups/joomla-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" "main"' ExecStartPost='/usr/bin/sync'
Timer
01
day of every month at02:35:00
sudo -e '/etc/systemd/system/main-fb.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'main-fb.timer' --now && sudo systemctl start 'main-fb' && sudo systemctl status 'main-fb' -l
[Unit] Description=Joomla Files Backup [Timer] OnCalendar=*-*-01 02:35:00 Persistent=true [Install] WantedBy=timers.target
Database
Database Auth
sudo mkdir -p '/var/lib/mysql/auth' && sudo -e '/var/lib/mysql/auth/joomla' && sudo chown -R 'mysql':'mysql' '/var/lib/mysql/auth/joomla' && sudo chmod '600' '/var/lib/mysql/auth/joomla' && sync
[mariadb-dump] user=joomla password=x
Service
mkdir -p ~/'backups' && sudo mkdir -p '/var/lib/mysql/tmp' && sudo chown -R 'mysql':'mysql' '/var/lib/mysql/tmp' && sudo chmod '600' '/var/lib/mysql/tmp' && sudo -e '/etc/systemd/system/main-db.service' && sudo sed -i 's/'CHANGEME'/'$USER'/g' '/etc/systemd/system/main-db.service'
[Service] Type=oneshot WorkingDirectory=/var/lib/mysql/tmp ExecStartPre='/usr/bin/mariadb-dump' --defaults-extra-file='/var/lib/mysql/auth/joomla' --single-transaction 'joomla_db' -r '/var/lib/mysql/tmp/joomla.sql' ExecStart='/usr/bin/gzip' -f '/var/lib/mysql/tmp/joomla.sql' ExecStart='/usr/bin/bash' -c '"/usr/bin/mv" "/var/lib/mysql/tmp/joomla.sql.gz" "/home/CHANGEME/backups/joomla-database-auto-"$$(date +%%Y-%%m-%%d)".sql.gz"' ExecStartPost='/usr/bin/sync'
Timer
- Every day at
02:45:00
sudo -e '/etc/systemd/system/main-db.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'main-db.timer' --now && sudo systemctl start 'main-db' && sudo systemctl status 'main-db' -l
[Unit] Description=Joomla Database Backup After=mariadb.service [Timer] OnCalendar=*-*-* 02:45:00 Persistent=true [Install] WantedBy=timers.target
Backup
- Create backup archive on server and transfer to client computer
Server
Stop Services
sudo systemctl stop nginx php-fpm
Backup Folder
cd '/var/www' && sudo tar -cvzf ~/'joomla-files-manual-'$(date +%Y-%m-%d)'.tar.gz' 'main' && cd ~ && sync
Backup Database
sudo mariadb-dump --defaults-extra-file='/var/lib/mysql/auth/joomla' --single-transaction 'joomla_db' -r ~/'joomla-database-manual-'$(date +%Y-%m-%d)'.sql' && sync
Start Services
sudo systemctl start nginx php-fpm
Client
Transfer Files To Client
scp espionage724@192.168.1.152:~/'joomla-files-'*'.tar.gz' espionage724@192.168.1.152:~/'joomla-database-'*'.sql' ~/'Downloads' && sync
Restore
Client
Uncompress Database
- This is only needed if restoring an automated database backup 4)
gunzip ~/'Downloads/joomla-database-'*'.sql.gz'
Transfer Files To Server
scp ~/'Downloads/joomla-files-'*'.tar.gz' ~/'Downloads/joomla-database-'*'.sql' espionage724@192.168.1.152:~
Remove Files
rm -f ~/'Downloads/joomla-files-'*'.tar.gz' ~/'Downloads/joomla-database-'*'.sql' && sync
Server
Stop Services
sudo systemctl stop nginx php-fpm
Restore Joomla Folder
cd '/var/www' && sudo tar -xvzf ~/'joomla-files-'*'.tar.gz' 'main' && sudo semanage fcontext --add --type 'httpd_sys_rw_content_t' '/var/www/main(/.*)?' && sudo restorecon -F -I -R '/var/www/main' && sudo chown -R 'nginx':'nginx' '/var/www/main' && cd ~ && sync
Drop Previous Database
sudo mariadb
DROP DATABASE joomla_db;
FLUSH TABLES;
EXIT
Re-create Databases
sudo mariadb
CREATE DATABASE joomla_db;
EXIT
Restore Database
sudo mariadb 'joomla_db' < ~/'joomla-database-'*'.sql' && sync
Reapply Permissions
sudo mariadb
GRANT ALL PRIVILEGES ON joomla_db.* to 'joomla'@'localhost' IDENTIFIED BY 'x';
FLUSH PRIVILEGES;
EXIT
Start Services
sudo systemctl start nginx php-fpm
Remove Backups
- Verify that Joomla works before running
rm ~/'joomla-files-'*'.tar.gz' ~/'joomla-database-'*'.sql' && sync
Batch Files
PHP-CGI
notepad++ "%UserProfile%\Desktop\Main php-cgi.bat"
CD "C:\php-"*"-nts-Win32-vs16-x64\" SET PHP_FCGI_MAX_REQUESTS="0" SET PHP_FCGI_CHILDREN="1" START "Main PHP-CGI" php-cgi.exe -b "127.0.0.1:9001" -c "%SystemDrive%\www\php\main-php.ini"
"%UserProfile%\Desktop\Main php-cgi.bat"
/var/www/wiki/data/pages/servers/windows/nginx/dokuwiki.txt · Last modified: by 127.0.0.1