install-dokuwiki

Install DokuWiki on Ubuntu with Nginx and Letsencrypt

In this post, I am going to share how to install DokuWiki on Ubuntu using Nginx and letsencrypt. Before going to install Dokuwiki, First of all I want to explain a little bit about Dokuwiki. It is a software to install your own wiki which is written in php language. It is a high versatile software that don’t need any database because it works on text files or templates.

Requirements to install DokuWiki on Ubuntu using Nginx

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

Check Update system packages

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get dist-upgrade

$ sudo reboot

 

Now restart the system, set system hostname and proceed to install php:

$ sudo hostnamectl set-hostname wiki.trickscage.net

Install PHP and required modules

Now you need to install php and modules. To install php and its modules run the following commands.

$ sudo apt-get -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-recode php-tidy php-xmlrpc \php-mbstring php-gettext php-gmp php-json php-xml php-common

Install Nginx and certbot-auto

Now you need to install Nginx webserver to get Dokuwiki certificate for the site.

$ sudo apt-get update$ sudo apt-get install wget nginx$ wget https://dl.eff.org/certbot-auto$ chmod +x certbot-auto$ sudo mv certbot-auto /usr/local/bin/certbot-auto

 

Finally, Download and Install Dokuwiki

Now you need to download and install Dokuwiki’s latest stable version from github releases by following link:

Click Here

$ export RELEASE=”2018-04-22a”$ wget https://github.com/splitbrain/dokuwiki/archive/release_stable_${RELEASE}.tar.gz

Extract archive file using tar

$ tar xvf release_stable_${RELEASE}.tar.gz

$ sudo mv dokuwiki-release_stable_${RELEASE} /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/

Send Request for letsencrypt SSL Cetificate

Stop Nginx then request for a certificate:

$ sudo systemctl stop nginx

To Request Certificate please run the following code:

# export DOMAIN=’wiki.yourdomain.com

# export EMAIL=”webmaster@yourdomain.com”

# certbot-auto certonly –standalone -d $DOMAIN \

–preferred-challenges http –agree-tos -n -m $EMAIL \

–keep-until-expiring

Now Configure Nginx with SSL

systemctl enable nginx

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

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

server {

 

listen 443 ssl;

server_name wiki.mydomain.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.mydomain.com/fullchain.pem;

ssl_certificate_key /etc/letsencrypt/live/wiki.mydomain.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.mydomain.com;

add_header Strict-Transport-Security max-age=2592000;

rewrite ^ https://wiki.mydomain.com$request_uri? permanent;

}

Replace all wiki.mydomain.com with your wiki domain name.

Check nginx syntax:

root@wiki:~# 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

$ sudo systemctl status php7.2-fpm.service nginx

Once you are done with the installation, you can remove the install.php file

Related Posts