Currently using a free-tier AWS EC2 instance with the following parameters:
Protip: save the .pem
file into .ssh
and make an alias in .zshrc
to quickly connect to the EC2 instance, as such:
alias dokuconnect="ssh -i ~/.ssh/<your key>.pem <username>@<ec2 instance>.compute.amazonaws.com"
All hosted on Namecheap since it's cheaper than Route53.
Stored the following config in sites-available
and symlinked in sites-enabled
:
server { listen 80; listen [::]:80; server_name sergey.wiki wiki.smirnov.nyc; return 301 https://$server_name$request_uri; } server { listen [::]:443 ssl; listen 443 ssl; server_name sergey.wiki|wiki.smirnov.nyc; # Maximum file upload size is 4MB - change accordingly if needed client_max_body_size 4M; client_body_buffer_size 128k; root /var/www/dokuwiki; index doku.php; ssl_certificate /etc/letsencrypt/live/sergey.wiki/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/sergey.wiki/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot #Remember to comment the below out when you're installing, and uncomment it when done. location ~ /(conf/|bin/|inc/) { deny all; } #Support for X-Accel-Redirect location ~ ^/data/ { internal ; } location ~ ^/lib.*\.(js|css|gif|png|ico|jpg|jpeg)$ { expires 365d; } location / { try_files $uri $uri/ @dokuwiki; } location @dokuwiki { # rewrites "doku.php/" out of the URLs if you set the userwrite setting to .htaccess in dokuwiki config page 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; } location ~ \.php$ { try_files $uri $uri/ /doku.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REDIRECT_STATUS 200; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # fastcgi_pass unix:/var/run/php5-fpm.sock; #old php version } }
Running 2018-04-22c “Greebo”, setup as standard.
Pending update to 2020-06-01 “Hogfather”, but since it's a release candidate and first major release in two years, I'll hold off.
Apart from the default extensions that come with Dokuwiki, I've found these plugins have greatly increased my usability of Dokuwiki:
aws configure
and enter in your keys and region
Install pip3 install boto3
, then modify the following file to your needs:
import boto3 import botocore import datetime import os import re import tarfile WIKI_PATH = "/var/www/dokuwiki" BACKUP_PATH = "~/backups" AWS_ACCESS_KEY = "your_access_key_here" AWS_SECRET_KEY = "your_secret_key_here" BUCKET_NAME = "your-bucket-name-here" BUCKET_KEY_PREFIX = "dokuwiki/" TARGET_DIRS = ['conf', 'data/attic', 'data/media', 'data/meta', 'data/pages'] dirs = [WIKI_PATH + '/' + d for d in TARGET_DIRS] datestring = re.sub('[^0-9]', '', datetime.datetime.now().isoformat()) filename = '{}/wiki-{}.tar.gz'.format(BACKUP_PATH, datestring) with tarfile.open(os.path.expanduser(filename), 'w:gz') as tar: for dir in dirs: tar.add(dir, arcname=os.path.basename(dir)) s3 = boto3.resource('s3') bucket = s3.Bucket(BUCKET_NAME) try: s3.Object(BUCKET_NAME, BUCKET_KEY_PREFIX + os.path.basename(filename)).put(Body=open(os.path.expanduser(filename), 'rb')) except botocore.exceptions.ClientError as e: error_code = int(e.response['Error']['Code']) print(error_code)
Scheduled to run daily at 10:00 UTC using crontab
.
Run crontab -e
and add the following line:
0 10 * * * python3 ~/scripts/s3-backup.py