wiki.allensmith.net

Personal "Rough Notes & Useful Links

User Tools

Site Tools


kb:linux:lts14lxcnginxphpdokuwiki

Lxc 1.0: DokuWiki in an Nginx & PHP Container

The below Dokuwiki Development Server is created & deployed using an lxc-clone of the already created Lxc 1.0 Nginx and PHP Container. In this example, the wiki will be found at http://dokuwiki.lxc/ (The container is dokuwiki and the website directory is / … which is stored at /var/www/html/)
Please Note: This document uses both the Command Shell and the Root Command Shell. That is why when Terminal Commands are given below, the command prompt that is expected (ending either in $ or #) is at the beginning of each line − so do not copy & paste that 1st character.

Create the Nginx & PHP Container to Install DokuWiki

  • Create the dokuwiki development container using an Overlayfs clone of nginx14lts
    $ sudo su
    # lxc-clone -o 14lts64-nginx -n dokuwiki -B overlayfs -s

    which produced the below output

    Created container dokuwiki as snapshot of 14lts64-nginx
    # exit
  • The default user & password for this just created container will be ubuntu & ubuntu
  • Start this just created container & Log-in to it:
    $ sudo lxc-start -n dokuwiki -d
    $ sudo lxc-console -n dokuwiki
  • Change the default password for the ubuntu user:
    $ passwd
    • set the password to something else (and remember it).
    • logout & log back in to ensure the password was set correctly.

Configure Nginx to use dokuwiki.lxc as a DokuWiki site

Please Note: The following Nginx rewrite rules – to enable DokuWiki to use “nice” URLs – work only if DokuWiki is installed in the webhosting root for the container. (e.g. http://dokuwiki.lxc/wiki:welcome will work.)
  • Replace the Nginx configuration file for the Virtual Server with an edited (for DokuWiki) version
    $ sudo mv /etc/nginx/sites-available/virtual /etc/nginx/sites-available/virtual.old
    $ sudo nano /etc/nginx/sites-available/virtual     # put the following into this empty file
    /etc/nginx/sites-available/virtual
    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
     
    # Default server configuration
    #
    server {
            listen 80 default_server;
            listen [::]:80 default_server;
     
            # SSL configuration
            #
            # listen 443 ssl default_server;
            # listen [::]:443 ssl default_server;
            #
            # Self signed certs generated by the ssl-cert package
            # Don't use them in a production server!
            #
            # include snippets/snakeoil.conf;
     
            root /var/www/html;
     
            # Add index.php to the list if you are using PHP
            index doku.php;
     
            server_name dokuwiki.lxc;
     
            # nice URL rewrite
            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;
            }
     
            # Security Rules from www.dokuwiki.org/security#deny_directory_access_in_nginx
            location ~ /(data|conf|bin|inc)/ {
              deny all;
            }
     
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then try the nice URL rewite.
                    try_files $uri $uri/ @dokuwiki;
            }
            location ~ /\.ht {
                    # deny access to .htaccess files, if Apache's document root
                    # concurs with nginx's one
                            deny all;
            }
     
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    try_files $uri =404;
            #       # With php5-cgi alone:
            #       fastcgi_pass 127.0.0.1:9000;
                    # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    }
If the container name is something other than dokuwiki, then edit the above server_name dokuwiki.lxc; line to use the .lxc version of the name for your container. (Mind the ending semicolon.)
  • Now restart the nginx & php-fpm services:
    $ sudo service nginx restart
    $ sudo service php5-fpm restart

Download & Install the DokuWiki Files

  • download the latest stable version of DokuWiki into ~/
    $ wget http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz

    This produced the following output:

    --2015-05-19 21:40:30--  http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
    Resolving download.dokuwiki.org (download.dokuwiki.org)... 46.4.55.201, 2a01:4f8:140:13e4::b00b
    Connecting to download.dokuwiki.org (download.dokuwiki.org)|46.4.55.201|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 3283317 (3.1M) [application/octet-stream]
    Saving to: ‘dokuwiki-stable.tgz’
    
    100%[===================================================>] 3,283,317    618KB/s   in 6.5s   
    
    2015-05-19 21:40:39 (496 KB/s) - ‘dokuwiki-stable.tgz’ saved [3283317/3283317]
  • From the download tarball, extract the directory structure by typing
    $ tar xzvf dokuwiki-stable.tgz
  • Now delete the tarball by typing
    $ rm dokuwiki-stable.tgz
  • change the name of the directory to where the wiki will be stored – which will be /var/www/html/ for the webserver root
    $ mv doku* html
  • remove the “testing” files in the webserver root (below mv command needs empty directory)
    $ sudo rm -R /var/www/html/*
  • move this directory into the web root, and set ownership – to allow access to this by typing dokuwiki.lxc
    $ sudo mv html  /var/www/
    $ sudo chown -R  www-data:www-data /var/www/html

Run the DokuWiki Installer Script

  • Once the DokuWiki installer has been run, delete the install.php file
    $ sudo rm /var/www/html/install.php

Suggested Post-Install Configuration

  • Log-in to the just created DokuWiki site
  • Admin » Configuration Settings
    • In the Display section:
      • Number of “trace” breadcrumbs. Set to 0 to disable. → set to 0
      • Use hierarchical breadcrumbs … → SELECT this
      • Top level for table of contents → 2
      • Use first heading for pagenames → set to Always
      • By default, DokuWiki will show all namespaces in the sitemap. … → SELECT this option
    • In the Links section:
      • Target window for external links → set to _blank
    • In the Advanced section:
      • Use nice URLs → set to .htaccess
      • Size in bytes up to which images referenced in CSS files should be embedded right into the stylesheet → set to 512
      • Use gzip Content-Encoding for xhtml → SELECT this
kb/linux/lts14lxcnginxphpdokuwiki.txt · Last modified: 2016/01/13 20:35 (external edit)