How to Install DokuWiki with Nginx and Let’s Encrypt SSL on Ubuntu 20.04

install dokuwiki ubuntu 20.04

DokuWiki is a free, open-source and highly versatile wiki software that doesn’t require a database. It is simple, easy to use and mainly aimed at creating documentation of any kind. It is specially designed for developer teams, workgroups and small companies. It offers very useful features that may not be available to other PHP based CMS.

Features

  • Built-in Access Control Lists
  • Open Source and Device independent
  • Customizable Interwiki links
  • Automatic table of contents generation
  • Support for over 50 languages
  • Index-based fast full-text search

In this tutorial, we will learn how to install DokuWiki with Let’s Encrypt SSL on Ubuntu 20.04.

Prerequisites

  • A server running Ubuntu 20.04.
  • A valid domain name pointed with your server IP. In this tutorial, we will use dokuwiki.linuxbuz.com domain.
  • A root password is set up in your server.

Step 1 – Install Required Dependencies

Before starting, update your system with the latest packages by running the following command:

apt-get update -y

Next, you will need to install some required dependencies in your server. You can install all of them by simply running the following command:

apt-get install apt-transport-https gnupg2 git unzip wget -y

After installing all the required dependencies, you can proceed to the next step.

Step 2 – Install Nginx and PHP

DokuWiki is written in PHP and runs on the webserver. So you will need to install the Nginx web server, PHP and other PHP extensions to your server.

Run the following command to install all of them:

apt-get install nginx php php-cli php-fpm php-gd php-xml php-zip php-curl -y

Once all the packages are installed, start the Nginx service using the following command:

systemctl start nginx

At this point, all required packages are installed in your server.

Step 3 – Download DokuWiki

First, change the directory to the Nginx web root directory and download the latest version of DokuWiki using the following command:

cd /var/www/html
wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz

Once the download is completed, extract the downloaded file by running the following command:

tar -xvzf dokuwiki-stable.tgz

Next, rename the extracted directory to DokuWiki using the following command:

mv dokuwiki-2020-07-29 dokuwiki

Next, change the ownership and permission of the DokuWiki directory as shown below:

chown -R www-data:www-data /var/www/html/dokuwiki
chmod -R 775 /var/www/html/dokuwiki

At this point, Dokuwiki is downloaded in your server.

Step 4 – Configure Nginx for DokuWiki

Next, you will need to create an Nginx virtual host configuration file to serve Dokuwiki. You can create it with the following command:

nano /etc/nginx/sites-available/dokuwiki.conf

Add the following lines:

server {
    listen 80;
    root /var/www/html/dokuwiki;
    index index.php index.html index.html;
     server_name dokuwiki.linuxbuz.com;

    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&$args last;
    }
 
    location ~ \.php$ {
        # Caution: be sure the php7.2-fpm.sock matches your version
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Save and close the file then activate the Nginx virtual host with the following command:

ln -s /etc/nginx/sites-available/dokuwiki.conf /etc/nginx/sites-enabled/

Next, verify the Nginx for any configuration error:

nginx -t

If everything is fine you should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, restart the Nginx and PHP-FPM service with the following command:

systemctl restart nginx
systemctl restart php7.4-fpm

At this point, Nginx is configured to serve Dokuwiki.

Step 5 – Secure DokuWiki with Let’s Encrypt SSL

Let’s Encrypt is a free and open certificate authority aims to create a more secure and privacy-respecting Web by promoting the widespread adoption of HTTPS.

First, you will need to install the Certbot client to manage the SSL. You can install it with the following command:

apt-get install python3-certbot-nginx -y

After the successful installation, run the following command to install the Let’s Encrypt SSL for your Dokuwiki website:

certbot --nginx -d dokuwiki.linuxbuz.com -m [email protected] --agree-tos

You will be asked to select whether or not to redirect HTTP traffic to HTTPS as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for dokuwiki.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/dokuwiki.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit Enter to download Let’s Encrypt SSL and configure Nginx to use the SSL. Once the installation has been finished, you should see the following output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/dokuwiki.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://dokuwiki.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=dokuwiki.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/dokuwiki.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/dokuwiki.linuxbuz.com/privkey.pem
   Your cert will expire on 2021-01-01. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot 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

At this point, your Dokuwiki website is secured with Let’s Encrypt SSL.

Step 6 – Access DokuWiki Web Interface

Now, open your web browser and access the Dokuwiki using the URL https://dokuwiki.linuxbuz.com/install.php. You should see the Dokuwiki installation screen:

dokuwiki installation

dokuwiki installation 2

Provide your Wiki name, Admin username, Email, Password and click on the Save button. Once the installation has been finished successfully, you should see the following screen:

dokuwiki installation success

Click on your new DokuWiki. You will be redirected to the DokuWiki Welcome screen:

dokuwiki welcome

Click on the Log in button. You will be redirected to the DokuWiki Login screen:

dokuwiki welcome screen

Provide your admin username, password and click on the Log In button. You should see the DokuWiki dashboard in the following screen:

dokuwiki dashboard

Congratulations! you have successfully installed DokuWiki with Let’s Encrypt SSL on Ubuntu 20.04 server. You can now start creating your own Wiki site using the DokuWiki.

You should also read the following article

Ansible for Absolute Beginner – Complete Guide

About Hitesh Jethva

I am Hitesh Jethva Founder and Author at LinuxBuz.com. I felt in love with Linux when i was started to learn Linux. I am a fan of open source technology and have more than 15+ years of experience in Linux and Open Source technologies.

View all posts by Hitesh Jethva