Install PmWiki

Overview

PmWiki is a simple and lightweight wiki that doesn't require a database. Instead, content for the wiki is stored in simple text files. Its only requirement is PHP, making it very simple to host using OpenBSD's openhttpd. PmWiki also does not require javascript in the user's browser, which helps improve accessibility.

Install

Download a copy of PmWiki. This guide uses the latest stable release.

First, download and extract the wiki:

$ ftp https://www.pmwiki.org/pub/pmwiki/pmwiki-latest.tgz
$ tar xvzf pmwiki-latest.tgz

Afterwards, move the files into httpd(8)'s web documents folder, then change the ownership:

# mv pmwiki-2.4.6 /var/www/htdocs/wiki.example.com
# chown -R www:daemon /var/www/htdocs/wiki.example.com

Replace wiki.example.com with your actual domain name.

Configure OpenHTTPd

Before you begin, make sure you have PHP installed.

Next, add a new block to httpd.conf(5). In /etc/httpd.conf we add:

server "wiki.example.com" {
	listen on * port 80
	location "/.well-known/acme-challenge/*" {
		root "/acme"
		request strip 2
	}
        root "/htdocs/wiki.example.com"
        location "*.php" {
                fastcgi socket "/run/php-fpm.sock"
        }
	directory {
		index "index.php"
	}
        connection max request body 104857600
}

Lines 8-10 above tell httpd(8) to evaluate any file that ends with .php as a PHP script. Line 3 says that the document root for web files is /htdocs/wiki.example.com. Keep in mind that httpd automatically chroots to /var/www/, so the actual path will be /var/www/htdocs/wiki.example.com/.

Line 11-13 tell httpd(8) to automatically serve index.php as the default file when a directory is requested by the user. For example, if a user requests https://wiki.example.com, he will actually receive https://wiki.example.com/index.php.

Line 14 tells httpd(8) to accept uploads as large as 100MB. httpd.conf(5) defaults to a maximum file size of 1MB, so this setting is necessary if you want to allow large file uploads for your wiki.

Next, create /var/www/htdocs/wiki.example.com/index.php and fill it with:

<?php include('pmwiki.php');

Then give it proper file ownership:

# chown www:daemon /var/www/htdocs/wiki.example.com/index.php

Finally, restart httpd:

# rcctl restart httpd

Use your browser to view http://wiki.example.com.

To add TLS, you can use either relayd for TLS acceleration (recommended) or openhttpd's TLS.

Configure PmWiki

Copy the sample configuration file and then edit it:

# cp /var/www/htdocs/wiki.example.com/docs/sample-config.php /var/www/htdocs/wiki.example.com/local/config.php

Documentation

Documentation for PmWiki is available at:

/var/www/htdocs/wiki.example.com/README.txt
/var/www/htdocs/wiki.example.com/docs/

Mirroring Content

When mirroring content, you want to skip these two files because they contain passwords:

/var/www/htdocs/wiki.example.com/local/config.php
/var/www/htdocs/wiki.example.com/wiki.d/SiteAdmin.AuthUser

Password Protection

To set the admin password, first generate a password hash using the link: https://wiki.example.com/pmwiki.php?action=crypt . Remember to replace wiki.example.com with the actual domain.

Note: PmWiki allows creation of password hashes using blowfish, so it's also possible to generate the hash inside OpenBSD using encrypt(1):

$ encrypt
TypeYourPasswordThenPressCtrl+d
$2b$09$tTFozEwRK8pqT3A4eoOypeQJNQEHtYL6cGrnPQ7mvu/cLf9MkO3F2

Next, in /var/www/htdocs/wiki.example.com/local/config.php, uncomment the line below:

$DefaultPasswords['admin'] = pmcrypt('secret');

Replace pmcrypt('secret'); with your hash surrounded by quote marks:

$DefaultPasswords['admin'] = '$2y$12$GAz0/65CeKpdTviP7z0IouUAWR1HNjuAgq4m94hQxwSvLu0FVVLOi';

Admins can also create new user accounts. Ask the user to visit https://wiki.example.com/pmwiki.php?action=crypt and send the admin the hash. Next, the admin should edit https://wiki.example.com/pmwiki.php?n=SiteAdmin.AuthUser, and create a new line with the desired username and password hash:

username: $2y$12$GAz0/65CeKpdTviP7z0IouUAWR1HNjuAgq4m94hQxwSvLu0FVVLOi

The password prompt page can be customized by editing /var/www/htdocs/wiki.example.com/wikilib.d/Site.AuthForm .

Clean URLs

The following URL rewrite rules can provide 'clean' URLs:

        location match "/pub/(.*)" {
                request rewrite "/pub/%1"
        }
        location match "/cookbook/(.*)" {
                request rewrite "/cookbook/%1"
        }
        location match "/uploads/(.*)" {
                request rewrite "/uploads/%1"
        }
        location match "/local/(.*)" {
                request rewrite "/local/%1"
        }
        location match "/favicon.(.*)" {
                request rewrite "/favicon.%1"
        }
        location match "/(.+)/(.+)" {
                request rewrite "/index.php?n=%1.%2?$QUERY_STRING"
        }
        location match "/(.+)" {
                request rewrite "/index.php?n=%1?$QUERY_STRING"
        }

Clone IRCNow

To clone the IRCNow almanack, you will need to install got:

$ ftp https://www.ircnow.org/software/almanack.tgz
$ tar xvzf almanack.tgz
$ got checkout almanack.git

Customize IRCNow wiki

To clone IRCNow's wiki, include these customizations in /var/www/htdocs/wiki.ircnow.org/local/config.php:

$EnablePathInfo = 1;
$EnableUpload = 1;
$ScriptUrl = 'https://wiki.example.com';
$PubDirUrl = 'https://wiki.example.com/pub';
$UploadDir = "/var/www/htdocs/wiki.example.com/pmwiki/uploads";
$UploadUrlFmt = "https://wiki.example.com/uploads";

Replace wiki.example.com with your custom domain.

Syncing with Got

On IRCNow, the almanack uses got for revision control. The got repo is stored in /var/git. It uses gotd to allow users to clone the repo, and gotwebd for web viewer.

Suppose a user in the commit group checks out a working tree in ~/almanack. Once a day, the user's cronjob syncs changes to the wiki files to the got repo:

@daily       openrsync -a --rsync-path=openrsync --exclude config.php --exclude wiki.d/SiteAdmin.AuthUser /var/www/htdocs/wiki.example.com/ ~/almanack
@daily       export GOT_AUTHOR="$USER <username@example.com>" && cd ~/almanack && got add -R ~/almanack && got commit -m "Daily backup"

Replace $USER and username@example.com with your real username and email.