Federated Wiki on Digital Ocean

At some point you may want to run your own Federated Wiki site, or perhaps set one up for friends or a class. We've had good luck installing on Digital Ocean, which currently offers very cheap hosting and a much simpler setup than services such as Amazon Web Services.

*Much of the content here is also applicable when installing Federated Wiki on other platforms.*

## Before You Start

Before you start there are some things to consider. You will very probably want a name to access your Federated Wiki, you will need to get yourself a domain, ask a friend or colleague for a domain name registrar that they use and like/trust.

Digital Ocean provides some tutorials to walk you though the various steps, we will be referring to them as we step through initial server setup, and installing the Federated Wiki server.

## Creating a Server

First, sign up for Digital Ocean. html

Once the sign up is complete you will have the option to create a new `droplet`.

The following will help you when following the tutorial . * A name for the droplet, e.g. `fedwiki`, * Choose a size, for a personal site or a small group site, we've found the $5/month option works perfectly fine. * A datacenter, choose one that is in the same area as you. * Choose an image, we will choose `Ubuntu 14.04.3 x32` which is the current 'Long Term Support' version of Ubuntu *supported until during 2019*. With less than 3GB of memory, it is recommended to use a 32-bit operating system. * It is recommended to use a SSH key to connect to the server, if you don't already have one click on `New SSH Key` to create one. tutorial

You should now have created a droplet, and be connected to it.

## Server Setup

We are going to follow the steps in the `New Ubuntu 14.04 Server Checklist`

* How To Connect To Your Droplet With SSH, *you should already be connected, but this covers the process in detail* tutorial * Initial Server Setup with Ubuntu 14.04 (ssh, sudo) tutorial * Additional Recommended Steps for New Ubuntu 14.04 servers (ufw, ntp, swap) tutorial

In the second tutorial replace `demo` with `wiki`. We will use this `wiki` account to run our Federated Wiki server later.

We will also setup the server to install patches automatically.

The recommended method for performing unattended upgrades is to use the `unattended-upgrades` package. Configuration is covered in in a tutorial and guide .

Some upgrades can require a server reboot, it is best to configure unattended upgrades to do this automatically.

In `/etc/apt/apt.conf.d/50unattended-upgrades` check that `Unattended-Upgrade::Automatic-Reboot` is `true`. **Also** ensure the `update-notifier-common` package is installed.

Also in `/etc/apt/apt.conf.d/50unattended-upgrades` you can uncomment the line

"${distro_id} ${distro_codename}-updates";

to apply updates as well as security patches. This will be needed if you choose to update Node.js automatically.

There is a tutorial on setting up a Node.js for production. While we broadly follow it, there are some slight variations in the steps below.

## Node.js Install

Node.js Long Term Support Release Schedule github

We will install Node.js using the package manager. guide .

Some of the Federated Wiki components include native code, so also install the optional build tools.

You will want to monitor for Node.js Security Updates, forum , or blog .

To install a security update, manually run the following commands:

sudo apt-get update sudo apt-get upgrade

This will also apply any other available updates at the same time.

Alternatively you could configure the unattended upgrade process to also apply Node.js updates.

## Nginx Install

We will use Nginx as a reverse proxy in front of the Federated Wiki server.

* How to Install Nginx on Ubuntu 14.04 LTS tutorial

The tutorial walks you though installing Nginx, and the basics of managing the Nginx process.

### Federated Wiki Install, and Configuration

We will now install the Federated Wiki software, configure it to restart automatically when the server is restarted, and configure Nginx to forward requests to it.

Federated Wiki is installed, and updated, by typing:

sudo npm install -g wiki

Add independent plugins to this install by adding more modules to the wiki where it has been globally installed.

cd /usr/lib/node_modules/wiki sudo npm install wiki-plugin-transport sudo npm install wiki-plugin-search

The tutorial uses the `pm2` process manager. Below are instructions for using `init` as a simpler alternative.

We can set up a Federated Wiki farm, that will automatically start when then the machine is restarted and we can start, and stop, using `sudo start wiki` and `sudo stop wiki`, by running the following commands, replacing `<user>` with the user you want to run wiki as:

initscript=" start on started networking stop on stopping networking respawn exec sudo -H -u wiki wiki -f " echo "$initscript" | sudo tee /etc/init/wiki.conf > /dev/null

If we start the Federated Wiki, `sudo start wiki`, we can check that it is running by typing `curl http://127.0.0.1:3000/` which should return the text `Found. Redirecting to welcome-vistors.html`.

We now need to configure Nginx to pass requests to the federated wiki software.

In `/etc/nginx/sites-available/default` we add

map $http_upgrade $connection_upgrade { default upgrade; '' close; }

before the `server` definition.

Following the tutorial, replace `example.com` with your domain name. This can contain a list, or wildcard, so that multiple names can be passed to the Wiki Farm. If for example I had registered the domain `example.wiki`, and wanted Federated Wiki sites to be any domain ending `example.wiki` I would use

server_name *.example.wiki;

if I also wanted a wiki site at `example.wiki` I would need to use

server_name example.wiki *.example.wiki;

We also need to use a slightly different location than that shown in the tutorial. Our modified server definition will look like that below:

server { listen 80; server_name example.wiki *.example.wiki; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:3000; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }

We also add a default route, to catch any requests for HOSTs we do not recognise.

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name _; return 444; }

It is also good practice to not advertise which version of Nginx we are running. This is done by turning off server tokens. In `/etc/nginx/nginx.conf` uncomment the line `server_tokens off;`.

Of course DNS would need to be setup to point the names we wish to use to our droplet, see tutorial and tutorial .

Restart Nginx:

sudo service nginx restart

You should now be able to access our new Federated Wiki site.

Next access your new Federated Wiki sites, sign in and claim them.

You will want to periodically: * Backup your wiki pages, * check for updates to Node.js and wiki