Set up dokuwiki on ubuntu 16.04

sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
sudo apt-get install php-fpm php-gd php7.0-xml


edit:/etc/php/7.0/fpm/php.ini
with cgi.fix_pathinfo=0

sudo service php7.0-fpm restart

content of /etc/nginx/site-available/wiki


server {    listen  80;
    root /usr/share/nginx/html;    
    index index.php index.html index.htm;
    server_name wiki.wikihost.tk;
    location / {        try_files $uri $uri/ /index.html;    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;    location = /50x.html {        root /usr/share/nginx/html;    }
    location ~ \.php$ {        try_files $uri =404;        fastcgi_pass unix:/run/php/php7.0-fpm.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include fastcgi_params;    }
    location ~ /\.ht {        deny all;    }
    location ~ /(data|conf|bin|inc)/ {        deny all;    }
location = / {
 return 301 http://$host/wiki/doku.php;
}
}



Test php:
sudo sh -c 'echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php'

open in browser
server_domain_or_IP_address/info.php

Install dokuwiki
cd ~
wget http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz

This will download a tarball into your current directory. Extract the directory structure by typing:

tar xzvf dokuwiki-stable.tgz

We can now delete the tarball by typing:

rm dokuwiki-stable.tgz

Let’s change the name of the directory to whatever path we’d like to access our wiki from. We will use wiki for this guide:

mv doku* wiki

We should move our directory into our web root. This will allow us to access our server by typing our domain followed by /wiki. Move the directory now:

sudo mv wiki /usr/share/nginx/www/

Before we continue, we need to do some additional security steps, or the installer will complain that it cannot access certain areas. Change to the directory you just moved:

cd /usr/share/nginx/www/wiki

The web process needs to have certain access to some files and directories within the wiki structure.

sudo chown -R www-data data
sudo chown www-data lib/plugins/
sudo chown www-data conf

Now, we are ready to install DokuWiki through the web browser using an installer script.

In your browser, go to your domain or IP address followed by the wiki sub directory and install.php:

server_domain_or_IP_address/wiki/install.php
 

 

Advertisements

Simple setup postgres db for django

sudo apt-get update
sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib
sudo su – postgres
psql
CREATE DATABASE uweb;
CREATE USER django WITH PASSWORD ‘django’;
ALTER ROLE django SET client_encoding TO ‘utf8’;
ALTER ROLE django SET default_transaction_isolation TO ‘read committed’;
ALTER ROLE django SET timezone TO ‘UTC’;
GRANT ALL PRIVILEGES ON DATABASE uweb TO django;

How to block specific user agents on nginx web server

To configure user-agent block list, open the nginx configuration file of your website, where the server section is defined. This file can be found in different places depending on your nginx setup or Linux distribution (e.g., /etc/nginx/nginx.conf, /etc/nginx/sites-enabled/<your-site>, /usr/local/nginx/conf/nginx.conf, /etc/nginx/conf.d/<your-site>).

location / {
if ($http_user_agent ~* (ahrefs|megaindex|majestic|mj12) ) {
return 403;
}

You can test it:

wget –user-agent “malicious bot” http://<nginx-ip-address&gt;

Render latest git date commit in django

Create file on server:

nano pull_repo.sh

#!/bin/sh

git –work-tree=/home/…web/ –git-dir=/home/…web/.git pull origin dev

git –work-tree=/home/…web/ –git-dir=/home/…web/.git log -1 –format=%cd > /home/…web/last.commit_date

chmod +x pull_repo.sh

Edit crontab:

crontab -e

Add line:

*/5 * * * * /home/…/pull_web.sh

In Django

decorator:

def prepare_commit_date(function):
    def wrap(request, *args, **kwargs):
        try:
            with open(os.path.join(BASE_DIR, "last.commit_date"), "r") as last_commit_date:
                request.commit_date = last_commit_date.readlines()[0].replace('\n', '')
        except Exception as ex:
            request.commit_date = str(ex.message)
        return function(request, *args, **kwargs)
    return wrap

view:

@prepare_commit_date
def index(request):
 return render(request, 'index.html', {})

template:

{{ request.commit_date }}