latest commit

This commit is contained in:
2025-12-19 15:24:03 +01:00
commit 4c19a78d62
4 changed files with 350 additions and 0 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Allan Christensen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

138
README.md Normal file
View File

@@ -0,0 +1,138 @@
# DokuWiki for Ubuntu 24.04
[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#)
[![Shell](https://img.shields.io/badge/shell-bash-121011)](#)
[![WebServer](https://img.shields.io/badge/server-nginx-009639)](#)
[![PHP](https://img.shields.io/badge/php-fpm-777BB4)](#)
[![App](https://img.shields.io/badge/app-dokuwiki-0098D4)](#)
[![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE)
Install DokuWiki on Ubuntu 24.04 server.
This is not a demo and not a quick experiment.
This is a production installer — designed for long-term use with hardened configs.
## Why this installer exists
Many tutorials skip permissions, hardening, and caching considerations. This one does it correctly and securely.
## What this installer does
✔ Creates isolated host + directory
✔ Applies correct permissions
✔ Removes installer files when done
✔ Supports HTTPS, caching and rate rules
## What this installer does *NOT* do
It wont stop you from running the script without reading the documentation like theres no tomorrow.
Skip the README, and whatever happens next is your headache, not a bug report.
---
## Requirements
You must already have:
✔ Nginx installed
✔ PHP-FPM running
### Optional Installers (if you need them — saves you some googling)
[Install Nginx + PHP-FPM on Ubuntu](https://git.x-files.dk/webserver/nginx-ubuntu)
---
## 1. Download
```
git clone https://git.x-files.dk/webapps/dokuwiki-ubuntu.git
```
```
cd dokuwiki-ubuntu
```
---
## 2. Install
```
sudo ./dokuwikiinstall <domain>
```
Example:
```
sudo ./dokuwikiinstall wiki.example.com
```
Generated paths:
| File/Dir | Purpose |
|---|---|
| `/var/www/<domain>` | DokuWiki installation |
| `/etc/nginx/conf.d/<domain>.conf` | Virtualhost |
| `/tmp/dokuwiki-postinstall` | Hardening script |
---
## 3. Web Setup
Visit:
```
http://<domain>/install.php
```
Create admin + finish setup.
---
## 4. PostInstall Hardening
```
sudo /tmp/dokuwiki-postinstall
```
This script:
✔ Removes installer
✔ Secures permissions
✔ Applies sane defaults
✔ Makes the wiki productionsafe
---
## HTTPS
Enable TLS with:
https://git.x-files.dk/webserver/nginx-snippets/src/branch/main/hostfiles/dokuwiki.443.conf
Optional caching (disabled by default):
```
# include /etc/nginx/nginx-snippets/cache-open-files.conf;
# include /etc/nginx/nginx-snippets/cache-statics.conf;
# include /etc/nginx/nginx-snippets/cache-js-css.conf;
```
---
## Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Nginx restart fails | Config syntax | `nginx -t` |
| PHP errors | Wrong FPM version | `systemctl status php8.3-fpm` |
| install.php still present | Postinstall not run | `sudo /tmp/dokuwiki-postinstall` |
---
### More Information
More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk)
---
### License
Licensed under the [MIT License](./LICENSE).
---

187
dokuwikiinstall Executable file
View File

@@ -0,0 +1,187 @@
#!/usr/bin/env bash
# Author : Allan Christensen
# First Created : 05-01-2022 (DD-MM-YYYY)
# Description : Installs DokuWiki on Ubuntu 24.04
# License : MIT License
#
# Are we root
#
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1 ; fi
#
# Get PHP-FPM version
#
phpfpm=$(systemctl list-unit-files --type=service | awk '/php[0-9]+\.[0-9]+-fpm\.service/ {sub(".service","",$1); print $1; exit}')
if [[ -z "$phpfpm" ]]; then printf "\nUnable to detect php-fpm version. Is PHP-FPM installed?\n\n" ; exit 1 ; fi
#
# Check if required services are running
#
for svc in nginx "$phpfpm"; do systemctl is-active --quiet "$svc" || { printf "\n%s is not running, cannot continue...\n\n" "${svc^}" ; exit 1 ; }; done
#
# Define variables and functions
#
hostname="$1"
#
# Function usage
#
usage () {
printf -- "\ndokuwikiinstall\n\n"
printf -- "Installs DokuWiki on Ubuntu\n\n"
printf -- "Usage:\n"
printf -- "sudo ./dokuwikiinstall <domain>\n"
printf -- "Examples:\n"
printf -- "sudo ./dokuwikiinstall wiki.something.xyz\n\n"
}
#
# Parse and validate input
#
if [[ $# -ne 1 ]]; then
usage
printf "ERROR: Exactly one argument (the domain only).\n\n"
exit 1
fi
# Convert to lowercase (domains are case-insensitive)
hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
# Ensure domain is not empty
if [[ -z "$hostname" ]]; then
printf "ERROR: Domain cannot be empty.\n\n"
usage
exit 1
fi
# Disallow spaces, slashes, or underscores
if [[ "$hostname" =~ [[:space:]/_] ]]; then
printf "ERROR: Domain cannot contain spaces, slashes, or underscores.\n\n"
exit 1
fi
# Validate domain format (RFC 1123)
if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then
printf "ERROR: Invalid domain format.\n"
printf "Example of valid input: wiki.example.com\n\n"
exit 1
fi
# Prevent accidental overwrite of existing Nginx config
if [[ -f "/etc/nginx/conf.d/${hostname}.conf" ]]; then
printf "\nERROR: A configuration file already exists for %s.\n" "$hostname"
printf "Refusing to overwrite existing site.\n\n"
exit 1
fi
# Check for existing references in other Nginx configs
hostcheck=$(grep -r --exclude="README.md" "$hostname" /etc/nginx/ 2>/dev/null || true)
if [[ -n "$hostcheck" ]]; then
printf "\nFound existing configuration mentioning %s — aborting to avoid collision.\n\n" "$hostname"
exit 1
fi
#
# Let's go
#
clear
#
# Ensure curl is available
#
for tool in curl unzip wget; do dpkg -s "$tool" &>/dev/null || apt install -y "$tool" ; done
#
# Clone nginx-snippets; if nginx-snippets exists then just pull latest changes
#
nginxsnippets="/etc/nginx/nginx-snippets"
repo="https://git.x-files.dk/webserver/nginx-snippets.git"
if [[ -d "$nginxsnippets/.git" ]]; then git -C "$nginxsnippets" pull --quiet; else git clone --quiet "$repo" "$nginxsnippets"; fi
#
# Download the latest DokuWiki
#
wikidir="/var/www/html/$hostname" ; mkdir -p "$wikidir"
curl -sL https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz | tar -xzf - -C "$wikidir" --strip-components=1 || { echo "Download or extraction failed"; exit 1; }
chown -R www-data: "$wikidir"
#
# Create a DokuWiki nginx configuration file
#
cp "$nginxsnippets/hostfiles/dokuwiki.80.conf" /etc/nginx/conf.d/"$hostname".conf
sed -i -- "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf
sed -i "s/PHPVERSION/$phpfpm/" /etc/nginx/conf.d/"$hostname".conf
#
# Restarting Nginx and PHP-FPM for changes to take effect
#
printf "\nRestarting services...\n"
systemctl restart "$phpfpm"
systemctl restart nginx
#
# Create post-install script
#
cat > /tmp/dokuwiki-postinstall <<EOF
#!/usr/bin/env bash
#
# DokuWiki Postinstall Script
#
#
# Are we root?
#
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi
#
# Harden DokuWiki
#
sed -i 's/^[[:space:]]*#\s*location /location /g' /etc/nginx/conf.d/"$hostname".conf
#
# Restart Nginx for changes to take effect
#
systemctl restart nginx
#
# Cleaning up
#
rm -f /tmp/dokuwiki-postinstall
EOF
chmod 755 /tmp/dokuwiki-postinstall
#
# DokuWiki post-install notice
#
wikinotice=$(cat <<EOF
-----------------------------------------------------------------------------------
IMPORTANT: Go to http://$hostname/install.php in order to complete the installation:
Don't worry about the warning on the right side of the page this will be
fixed as there still is a post install step to do.
Once done run the following command as root or using sudo.
sudo /tmp/dokuwiki-postinstall
-----------------------------------------------------------------------------------
EOF
)
#
# Print notice
#
printf '\n%s\n' "$wikinotice"
#
# All done
#
printf "\nAll Done...\n"
#
# End of script
#

4
last-tested Normal file
View File

@@ -0,0 +1,4 @@
------------------------------------
Last tested: 19-12-2025 (DD-MM-YYYY)
Environment: Ubuntu Server 24.04 LTS
------------------------------------