Table of Contents

Installing Dokuwiki

Migrating Dokuwiki?

If migrating Dokuwiki data from another server, all you need to do is move the /dokuwiki directory. To preserve last modified dates, archive as tar file prior to moving. After which, perform the usual permission settings and you are done. See servermove for more details.

Upgrading Dokuwiki?

This is much more straightforward, following the steps in the Dokuwiki upgrade guide. Main steps reproduced here:

  • Backup wiki: tar zcpfv dokuwiki-backup.tar.gz /var/www/dokuwiki
  • Download the diff from the Dokuwiki download page
  • Unpack and copy: tar zxvf dokuwiki-xxxx-xx-xx.tgz && sudo cp -af ./dokuwiki/* /var/www/dokuwiki/
  • Rename permissions: sudo chown -R www-data:www-data /var/www/dokuwiki
  • Upgrade plugins in Extension Manager

Optionally readjust the /dokuwiki/lib/tpl/dokuwiki/tpl_footer.php.

Fresh installation

Dokuwiki hosts all the required configuration and files on the host filesystem in its own /dokuwiki directory, so installation is as simple as unpacking the latest Dokuwiki distribution and setting up a virtual host to point towards the Dokuwiki directory.

Pre-requisites

The following fresh installation assumes an Ubuntu 20.04 host operating system with a PHP-enabled Nginx webserver. For instructions using other webservers / operating systems, a good starting point is the official Dokuwiki installation guide.

Since the /var/www directory is a common default for webservers (at least in 2021), we pull the Dokuwiki files and extract them into the /var/www/dokuwiki directory. For feature stability, the stable branch of Dokuwiki is preferred.

wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
tar -xvf dokuwiki-stable.tgz
rm dokuwiki-stable.tgz
sudo mv dokuwiki-*/ /var/www/dokuwiki

Configuring Nginx

All Dokuwiki functions are implemented as PHP scripts, which need to be installed and pointed to by the Nginx webserver. Ensure that PHP as well as its corresponding XML parser is installed. See the virtual host configuration example below for referencing the PHP library.

sudo apt install php-fpm php-xml php-mbstring

We can create a virtual host to point towards the Dokuwiki directory, so that the HTTP/HTTPS requests are forwarded correctly. For the Nginx webserver, this involves the creating the virtual host in sites-available/ and enabling the virtual host using a symbolic link from sites-enabled/. The relevant commands are listed below for completeness.

sudo vim /etc/nginx/sites-available/dokuwiki
sudo ln -s /etc/nginx/sites-available/dokuwiki /etc/nginx/sites-enabled
sudo nginx -t                 # check syntax
sudo systemctl reload nginx   # load configuration

Example virtual host configuration

A rudimentary virtual host configuration for Nginx is shown below, using PHP 7.4 from php-fpm. For the uninitiated, a good starting resource is the Nginx's beginner guide.

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/dokuwiki;
    index index.php; # essentially redirects to 'doku.php'

    # Enable PHP interpreter
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # PHP 7.4
    }
    
    # Prevent direct web access, see next section on security
    location ~ /(data|conf|bin|inc|vendor)/ {
        deny all;
    }
}

The default_server flag can only be applied to a single server block - in a fresh installation of Nginx, delete the symbolic link to the default configuration in sites-enabled/ as well (which contains another such reference).

sudo rm /etc/nginx/sites-enabled/default

Securing Dokuwiki

Dokuwiki relies on the PHP server to read and write files within the Dokuwiki directory in the filesystem (remember that the backend is not a database server!). Set the appropriate permissions, and ensure that only the relevant users on the server have write/execute access to the files (yes, the execute bit must be set for directories). By default, the PHP runs as the www-data user (belonging to its standalone group www-data).

# Change owner of files/directories
sudo chown -R www-data:www-data /var/www/dokuwiki
sudo usermod -a -G www-data [USER]
 
# Set file/directory permissions
find /var/www/dokuwiki -type f -exec chmod 0660 {} +
find /var/www/dokuwiki -type d -exec chmod 2770 {} +  # setgid

The permissions and security articles on Dokuwiki elucidate these principles in greater detail. These are a must-read!

Checking PHP user

To check the user used by the PHP server, create a PHP file to run the phpinfo() function within the Dokuwiki directory (or anywhere served by Nginx, really) with the appropriate access permissions, and navigate to the file in your web browser. The user will be listed in the configuration.

<?php phpinfo();?>

Remember to delete this file once done to prevent your PHP configuration from being leaked (and potentially exploited)!

Completing the installation

Without much other fanfare, open /install.php in the web browser to complete installation of Dokuwiki. It is recommended to enable access control lists (ACL) for more granular permissions between guests, registered users, and admins (this was why you chosen Dokuwiki over Mediawiki, no?).

Missing 'xml_parser_create' on installation page

If you encounter the "PHP function xml_parser_create is not available." error, especially on Ubuntu 20.04, this is likely because php-xml is not enabled by default. Remember to install the necessary package with sudo apt install php-xml.

Slow Dokuwiki search

If the search page of Dokuwiki is slow, check if php-mbstring has been installed. This particular module seems to fall through the cracks whenever users perform a fresh PHP install.

Delete the /install.php as an additional security precaution once installation is complete.

What's next?

Proceed on to the configuration page to customize your Dokuwiki installation.