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 with OpenBSD's openhttpd. It also does not require the user's browser to support javascript, which helps improve accessibility.

Install

Download a copy of PmWiki. In this guide, we'll grab the latest stable release.

$ ftp https://www.pmwiki.org/pub/pmwiki/pmwiki-latest.tgz
$ tar xvzf pmwiki-latest.tgz
$ doas mv pmwiki-2.2.141/ /var/www/htdocs/wiki.example.com
$ doas chown -R www:daemon /var/www/htdocs/wiki.example.com

Make sure to replace wiki.example.com with your actual domain name. For flexibility, we recommend you run your own nameserver using nsd and create a records for wiki.example.com.

Configure OpenHTTPd

Before you begin, make sure you have PHP installed.

Next, add a new block to /etc/httpd.conf:

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

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

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

Line 14 tells httpd that it can receive uploads as large as 100MB. By default, httpd is limited to only 1MB, so this setting is necessary if you want to allow large file uploads for your wiki.

While not required, it helps to put in /var/www/htdocs/wiki.example.com/index.php:

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

Then give it proper permissions:

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

Finally, restart httpd:

$ doas 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.

Configuring PmWiki

Copy the sample configuration file and then edit it:

$ doas cp /var/www/htdocs/wiki.ircnow.org/docs/sample-config.php /var/www/htdocs/wiki.ircnow.org/local/config.php

Edit /var/www/htdocs/wiki.ircnow.org/local/config.php.

Documentation

Make sure you get familiar with the docs. They are located in:

/var/www/htdocs/wiki.ircnow.org/README.txt
/var/www/htdocs/wiki.ircnow.org/docs/

Mirroring Content

When mirroring content, you want to skip the passwords in these two files:

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

Password Protect Pages

To change the password prompt page, edit Site.AuthForm.

By default, PmWiki allows creation of password hashes using blowfish, so in the command line, you can type:

$ encrypt
TypeYourPasswordThenPressCtrl+d
$2b$09$KcHFdL42rABog//yC9qehuv0wHgu19QqVHOnhW1zutMC/esVfDfwa

You can use these password hashes for https://example.com/index.php?n=SiteAdmin.AuthUser

Read user password from file

Please, create passwd file (pass.txt) in the local folder of the pmwiki location and update config.php like this:

$DefaultPasswords['admin'] = pmcrypt(trim(file_get_contents('pass.txt', true)));

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

Edit /var/www/htdocs/pmwiki/local/config.php:

$EnablePathInfo = 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";

Forking IRCNow

To fork the IRCNow almanack:

$ git clone git://got.ircnow.org/almanack

Syncing with Got

Creating the almanack got repo, assuming ~/almanack will be the working directory:

$ openrsync -a --rsync-path=openrsync --exclude config.php --exclude wiki.d/SiteAdmin.AuthUser /var/www/htdocs/wiki.ircnow.org/ ~/almanack
$ got init /var/git/almanack
$ got import -m "Import sources" -r /var/git/almanack ~/almanack

Delete the copy of the almanack and then check it out:

$ rm -r ~/almanack
$ cd ~/
$ got checkout /var/git/almanack

Then, set up a cronjob as a regular user:

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

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