Personal Wiki Setup

Yay, I've convinced someone to create their own personal wiki! The process is fairly straightforward. If you encounter any difficulty, feel free to reach out by twitter (@chrisshroba) or email (chrisshroba at gmail).

I use Digital Ocean (Disclaimer: sign up with that link and you get $10, I get $25). It gives you full SSH access to a server on which you can install and run anything you'd like. I use it for my wiki, blog, file server, and to host small side projects. I pay $5/month for my server (the cheapest you can buy from them, and you probably won't find one elsewhere for cheaper), and I think $60/year is more than reasonable for everything I'm getting out of my server. Go ahead and sign up and create a server (or droplet, as they call it - one droplet in the vast digital ocean, so to speak!).

If you'd rather, you can also use a website hosting provider instead, as long as it supports PHP. I have no experience with this route, but I would check out Namecheap, Bluehost, or Dreamhost if you want to go this route. If you do this, you will not have full root SSH access to the server, but you should have everything you need to host the wiki. If you go this route, I would just Google for a tutorial for installing Dokuwiki on your chosen host. The rest of this tutorial assumes you're using Digital Ocean.

Once you've created your first server and ssh'ed into it, you need to install a web server. The web server is the software that handles all incoming requests to your server and passes them off to dokuwiki. If you use your server for things besides the wiki, the web server actually routes all requests to where they need to go. For example, on my site, it routes wiki.shroba.io to my wiki, blog.shroba.io to my blog, and drop.shroba.io to my basic file server.

For this step, Digital Ocean has published a wonderful tutorial, which you can view here.

Follow the tutorial and then return here! When they mention server_domain_or_IP_address, just put in the IP address of your server if you don't already have a domain name linked up to it. We will set up a domain name later, but a domain name can take up to 24 hours to be registered with the DNS servers around the world (though I've found it's usually closer to an hour), so we will skip that for now.

Try creating and editing some pages. Congratulations! You have a working wiki!

The URL of your wiki is currently pretty ugly… something like http://107.170.38.184/wiki/doku.php?id=page. First we'll change the part of the URL after the IP address. There's a tutorial on Dokuwiki's site here - you'll want to follow the directions under Option 1 for Nginx. When I did this, I had some difficulties, so if things don't work out for you, you can copy the dokuwiki setup from my Nginx config file from here, which is what's currently running on this site. You'll want to change line 3 to have your IP address instead of wiki.shroba.io w, and I explain the w later on this page. You can edit this later again when you have a domain name.

After doing this, your wiki's pages' URLs should look a lot nicer: for example, 107.170.38.184/todo instead of 107.170.38.184/wiki/doku.php?page=todo.

We might as well take a few minutes to buy a domain name. Like many people I've talked to, I use Namecheap to buy my domains, but there are many other options as well. Go ahead and search for a domain to buy and register it now. You can then follow this tutorial to point your domain at Digital Ocean's name servers, and this tutorial to let Digital Ocean know what server to route requests to for your domain. In the second tutorial, you can skip steps 1 and 2, as they are covered by the first tutorial.

This can take up to a day to take effect, but will likely take significantly less time than that (30-90 minutes, in my experience). Now you can go back to your Nginx config file and edit your server_name line to include your domain name. Put it after your IP address (separated by a space) if you'd like to still be able to access your wiki by the IP address, a good idea if the domain name settings have not yet propagated. Then restart Nginx to reflect your changes: sudo /etc/init.d/nginx restart.

Note, by default you'll only be able to use your domain without a subdomain. For example, with the steps I've listed, I'd be able to use shroba.io as my domain, but not wiki.shroba.io. To allow subdomains to be used, follow this tutorial, or just make your DNS settings page in Digital Ocean look like mine but with your domain and IP address:

Click to make the picture bigger. Also, note the period after the domain name in the CNAME record.

This step is optional, but incredibly useful. I've configured my laptop to alias w/ to wiki.shroba.io/, so in my browser, I can replace wiki.shroba.io with just w, which makes navigating to pages extremely fast. For example, my URL bar currently reads w/wiki/setup, which is less than half the number of characters as wiki.shroba.io/wiki/setup.

To do this, open the file /etc/hosts for editing*. You'll need to modify it as root: sudo nano /etc/hosts. This file maps domains to IP addresses and bypasses DNS lookup for those domains. This file is what causes localhost, for example, to map to 127.0.0.1.

Add a line to the end of the file of the form 107.170.38.184 w, replacing my IP address with your own. This line says that when you navigate to w/ on your computer, that request should be sent to your IP address.

To make this go to your wiki, you'll need to edit your Nginx config file to include w as a server name. Again, reference my config file to see what this looks like. Restart Nginx after this change: sudo /etc/init.d/nginx restart.

The first time you use this alias, you may have to type it in your browser as http://w/, but after that you should be able to just use w.

*I have not confirmed this, but according to Google, the file is c:\Windows\System32\Drivers\etc\hosts on Windows

I didn't care for the default theme (aka template) of dokuwiki, and you've probably noticed your wiki looks different than mine. You can browse templates here and install them in the Extension Manager. I use Bootstrap3.

You can search and install plugins from the Extension Manager, or search and filter here. I have a list of plugins that I use here. I also recommend checking out my friend Ivan's plugin page here.

Think about how awful it would be to lose all of your data in the event your server crashed or you somehow accidentally deleted your data directory. You should definitely back up your wiki. Mine backs up to GitHub within 2 minutes of any change. This has the added benefit of giving me a complete history of every page in the wiki, in case I ever deleted a page accidentally or wanted to remember something that had previously been on it.

To set this up, I first initialized a git repo in the data directory for the wiki on my server, which for my server is at /usr/share/nginx/www/wiki/data:

git init
git add -A
git commit -m"Initial Commit"

I then set up a private repository in github, and set it as my repo's remote host:

git remote add origin git@github.com:chrisshroba/wiki.git
git push -u origin master

You can copy these lines from Github - it should provide them once you set up your repository there.

Next, I create a backup script which will automatically add all files in my data folder to the repository and commit it. Create the file /usr/local/bin/backup_wiki as root (using sudo), and put this inside:

#!/usr/bin/env bash

pushd /usr/share/nginx/www/wiki/data
git add -A
git commit -m"Backed up at $(date)"
git push
popd

Now, running backup_wiki in a shell will backup the wiki with a commit message that contains the current date and time (in the timezone of your server). To make this run automatically in a given interval, we can set up a cronjob to run, which is very easy.

Run crontab -e to edit cron file, and at the end of the file, add the following line and save the file:

*/2 * * * * /usr/local/bin/backup_wiki

This runs your script every 2 minutes, and backs up your data if there has been a change within the last 2 minutes. If not, when it attempts to commit, nothing will happen because there will be no changes, and when it attempts to push, Github will let it know that nothing needs to be pushed. If you'd like it to run less frequently, change the 2 to the number of minutes between runs, up to 59. If you want it to back up less frequently than that, check out this cron tutorial for the syntax, and Crontab.guru to verify that the cron expression you come up with will do what you expect.

Now make a change to some page on your wiki and check on Github to see if the page there is updated after the amount of time you chose. You'll want to look in the /pages directory of you repository - this is where the raw text files of your wiki pages are stored. Other directories contain things like search indices and media files. If you find yourself uploading many (or any) large media files to your wiki, you should only backup the /pages directory instead, as Github is mainly intended for backing up non-binary files, and Github may yell at you or even remove your repository if it exceeds a certain size (around 1GB).

Congratulations! You've set up your wiki. If you've made it this far, I'd love it if you let me know, so I know I didn't write this tutorial in vain!