We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Install DokuWiki on Ubuntu 22.04|20.04|18.04

Learn how to – How To Install DokuWiki on Ubuntu 22.04|20.04|18.04.

DokuWiki is a free and open source wiki software written in PHP. DokuWiki is highly versatile and doesn’t require a database since it works on plain text files. It has a syntax similar to the one used by MediaWiki. This guide will cover the steps to install DokuWiki on Ubuntu 22.04|20.04|18.04 with Nginx and Letsencrypt SSL certificate for encryption.

DokuWiki installation pre-requisites:

  • Updated system
  • PHP and php-fpm
  • Nginx or Apache web server
  • certbot-auto for requesting a Certbot certificate

Let’s kick off by making sure all software requirements are installed.

Step 1: Update system packages

Make sure your apt index and all software packages are updated.

sudo apt update

After rebooting the system, set system hostname and proceed to install php and all required modules:

sudo hostnamectl set-hostname wiki.example.com

Step 2: Install php and required modules

We now need to install php and some php modules required by DokuWiki. Run the following commands to get everything installed.

sudo apt -y install php php-curl php-apcu php-fpm php-bcmath php-gd php-intl php-pear php-imap php-memcache libapache2-mod-php php-pspell php-tidy php-xmlrpc php-mbstring php-gmp php-json php-xml php-common

Confirm the version of PHP on your system.

$ php -v
PHP 8.1.2 (cli) (built: Aug  8 2022 07:28:23) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

To get a list of php extensions installed on your system, use php -m command:

php -m

Step 3: Install Nginx and certbot-auto

Let’s install nginx webserver and certbotwhich we’ll later use to get a certificate for DokuWiki site.

sudo apt update
sudo apt install wget nginx certbot

Step 4: Download and Install DokuWiki

Before downloading any version of DokuWiki, check Downloads page for the latest stable release.

wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz

Extract DokuWiki archive using tar

tar xvf dokuwiki-stable.tgz
sudo mv dokuwiki-*/ /var/www/html/dokuwiki

Change ownership of /var/www/html/dokuwiki to www-data user and group.

sudo chown -R www-data:www-data /var/www/html/dokuwiki/

Step 5: Configure Nginx Proxy for DokuWiki

You can have DokuWiki on http or https.

Option 1: Using Nginx without SSL certificate

If you don’t need SSL connection you can configure Nginx without https section. Create Dokuwiki virtualhost file.

sudo vim /etc/nginx/conf.d/dokuwiki.conf

Paste and modify these settings.

# Dokuwiki Nginx configuration
server {
  listen 80;
  server_name wiki.example.com;
  root /var/www/html/dokuwiki/;

 access_log /var/log/nginx/dokuwiki.access.log;
 error_log /var/log/nginx/dokuwiki.error.log;

 index index.html index.php doku.php;

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 last;
 }

location ~ /(data|conf|bin|inc)/ {
 deny all;
 }

location ~* .(css|js|gif|jpe?g|png)$ {
 expires 1M;
 add_header Pragma public;
 add_header Cache-Control "public, must-revalidate, proxy-revalidate";
 }

location ~ .php$ {
 fastcgi_split_path_info ^(.+.php)(/.+)$;
 fastcgi_pass unix:/var/run/php/php-fpm.sock;
 fastcgi_index index.php;
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_intercept_errors off;
 fastcgi_buffer_size 16k;
 fastcgi_buffers 4 16k;
 }

location ~ /.ht {
 deny all;
 }
}

Don’t forget to replace wiki.example.com with your domain name. Once done test Nginx configuration syntax:

$ sudo nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart nginx service

sudo systemctl restart nginx

Confirm that the service is started without errors:

$ systemctl status nginx
â—Ź nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-10-05 18:11:17 EAT; 7s ago
       Docs: man:nginx(8)
    Process: 53704 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 53705 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 53706 (nginx)
      Tasks: 2 (limit: 9460)
     Memory: 2.6M
        CPU: 23ms
     CGroup: /system.slice/nginx.service
             ├─53706 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             └─53707 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Oct 05 18:11:17 jammy systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 05 18:11:17 jammy systemd[1]: Started A high performance web server and a reverse proxy server.

Open your browser and access http://wiki.example.com/install.php.

Option 2: Using Nginx without SSL certificate

Stop nginx since certbot-auto will bind to port 80

sudo systemctl stop nginx

Then request for a certificate:

export DOMAIN='wiki.example.com'
export EMAIL="admin@example.com"
sudo certbot certonly --standalone -d $DOMAIN 
 --preferred-challenges http --agree-tos -n -m $EMAIL 
 --keep-until-expiring

If successful, certbot will give you a successful message:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for wiki.ownyourlife.com.ng
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wiki.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wiki.example.com/privkey.pem
   Your cert will expire on 2022-01-27. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Create Dokuwiki virtualhost file.

sudo vim /etc/nginx/conf.d/dokuwiki.conf

Add the following content, modify to suit your use case. Replace wiki.example.com with your domain name.

# Dokuwiki Nginx configuration
server {

listen 443 ssl;
 server_name wiki.example.com;
 root /var/www/html/dokuwiki/;

 access_log /var/log/nginx/dokuwiki.access.log;
 error_log /var/log/nginx/dokuwiki.error.log;
 
 ssl on;
 ssl_certificate /etc/letsencrypt/live/wiki.example.com/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/wiki.example.com/privkey.pem;
 ssl_session_timeout 5m;
 ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers on;

 index index.html index.php doku.php;

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 last;
 }

location ~ /(data|conf|bin|inc)/ {
 deny all;
 }

location ~* .(css|js|gif|jpe?g|png)$ {
 expires 1M;
 add_header Pragma public;
 add_header Cache-Control "public, must-revalidate, proxy-revalidate";
 }

location ~ .php$ {
 fastcgi_split_path_info ^(.+.php)(/.+)$;
 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
 fastcgi_index index.php;
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_intercept_errors off;
 fastcgi_buffer_size 16k;
 fastcgi_buffers 4 16k;
 }

location ~ /.ht {
 deny all;
 }
}

# Redirect http to https
server { 
 listen 80;
 server_name wiki.example.com;
 add_header Strict-Transport-Security max-age=2592000;
 rewrite ^ https://wiki.example.com$request_uri? permanent;
}

Replace all existence of wiki.example.com with your wiki domain.

Check nginx syntax:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If no error, restart nginx and php-fpm

sudo systemctl restart php-fpm nginx

Step 6: Configure DokuWiki from Web interface

Start DokuWiki configuration by opening the link: https://wiki.mydomain/install.php, you will get installation page like below:

Provide admin user details, under,Initial ACL policy choose your policy from one of:

  • Open Wiki – Open for everyone
  • Public Wiki – read for all, uploads and edits for registered users
  • Closed Wiki – Access only for registered users

Check whether you want to Allow users to register themselves

When done, click Save. The wiki page should now be ready.

Click “your new DokuWiki” to get to DokuWiki home page.

Step 8: Adding users to DokuWiki

If you had selected “Closed Wiki | Public” as your ACL policy, you will be given login page for edits. Log in with admin account you created earlier to start adding other users to the system:

Click “Admin” icon at the top of the page, this will take you to admin page:

Click on “User Manager” to get add user page:

Add User details and click “Add” button. After adding a user, you can assign ACL on “Access Control List Management” page.

Select from given Permissions.

In our next Wiki guides, I’ll cover how to install plugins on DokuWiki to extend its functionalities.

2
33.626,55