How to install DokuWiki with Nginx and encrypt SSL on CentOS 8

How to install DokuWiki with Nginx and encrypt SSL on CentOS 8

DokuWiki is an easy-to-use and versatile open source Wiki software that does not require a database. It is loved by users for its clear and readable syntax. Easy to maintain, backup and integration make it an administrator’s favorite. The built-in access control and authentication connectors make DokuWiki particularly useful in an enterprise environment, and its plethora of plugins provided by its vibrant community allows the use of a wide range of use cases beyond traditional wikis. This tutorial will show you how to install DokuWiki on a new CentOS 8 server.

Claim

Make sure your server meets the following requirements.

  • Web server software supporting PHP (Apache, NGINX, IIS, Lighttpd, LiteSpeed)
  • PHP 5.6 or higher. New versions are strongly recommended.

prerequisites

  • A CentOS 8 operating system.
  • Non-root user with the following permissions sudo privilege.

Initial steps

Check your CentOS version:

cat /etc/centos-release# CentOS Linux release 8.0.1905 (Core)

Set the time zone:

timedatectl list-timezonessudo timedatectl set-timezone 'Region/City'

Update your operating system package (software). This is an important first step because it ensures that you have the latest updates and security fixes for the operating system’s default packages:

sudo dnf update -y

Install some basic packages that are necessary for basic management of CentOS operating system:

sudo dnf install -y curl wget vim git unzip socat bash-completion epel-release

Step 1-install PHP and PHP extensions

Install PHP and required PHP extensions:

sudo dnf install -y php php-cli php-fpm php-gd php-xml php-zip

To display PHP compiled in the module, you can run:

php -mctypecurlexiffileinfo. . .. . .

Check PHP version:

php --version# PHP 7.2.11-1-(cli) (built: Oct 26 2019 14:14:18) ( NTS )# Copyright (c) 1997-2018 The PHP Group# Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies# with Zend OPcache v7.3.11-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies

Start and enable the PHP-FPM service:

sudo systemctl start php-fpm.servicesudo systemctl enable php-fpm.service

Step 2-Install the acme.sh client and obtain the “Let’s Encrypt” certificate (optional)

There is no need to protect your website with HTTPS, but it is a good practice to secure your website traffic. To get a TLS certificate from Let’s Encrypt, we will use the acme.sh client. Acme.sh is a simple UNIX shell software for obtaining TLS certificates from Let’s Encrypt with zero dependencies.

Download and install acme.sh:

sudo su - rootgit clone https://github.com/Neilpang/acme.sh.gitcd acme.sh ./acme.sh --install --accountemail [email protected]source ~/.bashrccd ~

Check the acme.sh version:

acme.sh --version# v2.8.2

Get RSA with ECC / ECDSA Your domain / hostname certificate:

# RSA 2048acme.sh --issue --standalone -d example.com --keylength 2048# ECDSAacme.sh --issue --standalone -d example.com --keylength ec-256

If you want to test with fake certificate, you can add --staging Mark the above command.

After running the above command, your certificate and key will be located at:

  • For RSA: /home/username/example.com table of Contents.
  • For ECC / ECDSA: /home/username/example.com_ecc table of Contents.

To list the certificates you issued, you can run:

acme.sh --list

Create a directory to store your certificates. We will use /etc/letsencrypt table of Contents.

mkdir -p /etc/letsecnrypt/example.comsudo mkdir -p /etc/letsencrypt/example.com_ecc

Install / copy the certificate to the / etc / letsencrypt directory.

# RSAacme.sh --install-cert -d example.com --cert-file /etc/letsencrypt/example.com/cert.pem --key-file /etc/letsencrypt/example.com/private.key --fullchain-file /etc/letsencrypt/example.com/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"# ECC/ECDSAacme.sh --install-cert -d example.com --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"

All certificates will be automatically renewed every 60 days.

After obtaining the certificate, log out from the root user and return to the regular sudo user:

exit

Step 3-install and configure Nginx

DokuWiki will run on any web server that supports PHP. In this tutorial, we will use Nginx. If you prefer Apache or another web server, you can use it instead of Nginx.

Download and install NGINX from the CentOS repository:

sudo dnf install -y nginx

Check Nginx version:

sudo nginx -v# nginx version: nginx/1.14.2

Configure Nginx:

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

Copy / paste the following Nginx configuration and save it:

server {    listen [::]:443 ssl;    listen 443 ssl;
    listen [::]:80;
    listen 80;
    # RSA    ssl_certificate /etc/letsencrypt/example.com/fullchain.pem;    ssl_certificate_key /etc/letsencrypt/example.com/private.key;    # ECC    ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.pem;    ssl_certificate_key /etc/letsencrypt/example.com_ecc/private.key;
    server_name wiki.example.com;
    root /var/www/dokuwiki;
    index index.html index.htm index.php doku.php;
    
    client_max_body_size 15M;
    client_body_buffer_size 128K;
    
    location / {
        try_files $uri $uri/ @dokuwiki;
    }
    
    location ^~ /conf/ { return 403; }
    location ^~ /data/ { return 403; }
    location ~ /.ht { deny all; }
    
    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 ~ .php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Check Nginx configuration:

sudo nginx -t

Reload Nginx:

sudo systemctl reload nginx.service

Step 4-install DokuWiki

Create a document root directory:

sudo mkdir -p /var/www/dokuwiki

Navigate to the document root:

cd /var/www/dokuwiki

Download the latest stable version of DokuWiki from the DokuWiki download page:

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

Extract the DokuWiki archive:

sudo tar xvf dokuwiki-stable.tgzsudo rm dokuwiki-stable.tgzsudo mv dokuwiki-2018-04-22b/* . && mv dokuwiki-2018-04-22b/.* .sudo rmdir dokuwiki-2018-04-22b/

Change ownership /var/www/dokuwiki Directory to www-data:

sudo chown -R nginx:nginx /var/www/dokuwiki

Run sudo vim /etc/php-fpm.d/www.conf And set users and groups to nginx. Initially, it will be set up as users and groups apache.

sudo vim /etc/php-fpm.d/www.conf

Restart php7.3-fpm.service:

sudo systemctl restart php7.3-fpm.service

Open DokuWiki setup script, install.php, In your browser and set up DokuWiki. The installation script will check the availability of the required PHP functions and the required file permissions. It also creates an initial administrator account and an initial ACL policy. To run the installer, open http://wiki.example.com/install.php In your browser, then follow the instructions.

Step 5-access the DokuWiki web interface

Open a web browser and enter the URL http://example.com/install.php. You will be redirected to the following page:

Provide all necessary information such as super username, email, password. then click save Button. After the installation is successfully completed, you will see the following page:

Set username and password

Now click Your new DokuWiki. You should see the following page:

DokuWiki has been successfully installed

Now click on the login button. You will be redirected to the following page:

log in

Now provide your administrator username and password. then click recording in Button. You should see the DokuWiki dashboard in the following pages:

Welcome to DokuWiki

After successful configuration, delete install.php Files in DokuWiki root directory:

sudo rm /var/www/dokuwiki/install.php

Congratulations! You have successfully installed and configured DokuWiki on your CentOS 8 server. Now you can easily create your own Wiki website using DokuWiki.

Sidebar