User Tools

Site Tools


install_nginx_and_dokuwiki_on_fedora_server_29

Install NGINX and DokuWiki on Fedora Server 29

This instance of DokuWiki is installed along with NGINX on Fedora Server 29. This page describes the installation process for future references.

Install NGINX and PHP-FPM

dnf install nginx php-fpm php-json
systemctl start nginx
systemctl enable php-fpm
systemctl enable nginx

Configure Firewall

firewall-cmd --list-all
firewall-cmd --permanent --remove-service=cockpit
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Change Default Document Root

vim /etc/nginx/nginx.conf

    root /var/www/html;

systemctl reload nginx

Change PHP-FPM Running User/Group

The RPM package sets the user and group to apache. I want it to run under nginx instead.

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

    user nginx
    group nginx

systemctl reload php-fpm

Download DokuWiki

wget https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
tar xf dokuwiki-stable.tgz 
cd /var/www/html
cp -r ~/dokuwiki-2018-04-22b/ wiki
chown nginx:nginx -R wiki

Configure SELinux

Fedora has SELinux enabled by default, which prevents DokuWiki from modifying files under /var/www.

Option 1: Turn off SELinux

I didn't go this route because it looks dangerous.

sestatus 
getenforce 
setenforce 0

Option 2: Change file labels

dnf install policycoreutils-python-utils
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/wiki/.*'
cd wiki
ls -Z
restorecon -v -R .

Option 3: Turn permissive mode

I didn't test this but it should work.

semanage permissive -a httpd_t

Install HTTPS Certificates

DokuWiki installation process needs password inputs, so installing HTTPS certificates MUST come before that.

dnf install certbot-nginx
certbot --nginx

Renew automatically

crontab -e

    0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew

crontab -l

Install DokuWiki

Before going through install.php, I configured NGINX as follows.

vim /etc/nginx/nginx.conf

    http {
        types_hash_max_size 4096;
        server {
            location = / {
                return 302 https://$host/wiki/;
            }
            location ~ /(conf|bin|inc)/ {
                deny all;
            }
            location ~ /data/ {
                internal;
            }
        }
    }

systemctl reload nginx

After going through install.php, remove it.

Configure URL Rewrite

I followed https://www.dokuwiki.org/rewrite#nginx and the following options were needed.

vim conf/local.php

    $conf['basedir'] = '/wiki/';
    $conf['userewrite'] = '1';
    $conf['useslash'] = 1;

vim /etc/nginx/nginx.conf

    http {
        server {
            location /wiki/ {
                index doku.php;
                try_files $uri $uri/ @dokuwiki;
            }
            location @dokuwiki {
                rewrite	^/wiki/_media/(.*)		/wiki/lib/exe/fetch.php?media=$1 last;
                rewrite	^/wiki/_detail/(.*)		/wiki/lib/exe/detail.php?media=$1 last;
                rewrite	^/wiki/_export/([^/]+)/(.*)	/wiki/doku.php?do=export_$1&id=$2 last;
                rewrite	^/wiki/(?!lib/)(.*)		/wiki/doku.php?id=$1&$args last;
            }
        }
    }
install_nginx_and_dokuwiki_on_fedora_server_29.txt · Last modified: 2019/01/19 20:42 by root