How-To: Fargo Self-Hosted Publishing - Hosting Fargo blog content

Tweet This Post

Introduction

  • Over the last weekend I was trying to work out what alternatives I had to storing this stream blog somewhere other than S3. Up until Sunday, this blog had been residing on an Amazon S3 bucket but this storage was actually starting to cost me money so I decided to find a way to store it on my existing VPS (virtual private server). In this instance the same VPS that is running my fargoPublisher. See this how-to article on how to set that up.

  • I started the journey by looking at an article that Dave wrote on hosting your site on GitHub Pages. This only took a few minutes to configure as I already had a GitHub page set-up. I played around for a bit but soon got fed up having to commit and sync all the time. There had to be a more seamless solution with minimal effort required. Don't get me wrong, this is a great way to store your pages away from a paid solution such as Amazon S3 but personally it didn't cut it for me. For those wanting to try this solution you can also setup a custom domain for your GitHub pages.

  • So call me a control freak, I wanted total control of where my site was stored.

  • If you notice, part of the config for using GitHub Pages as storage there is that there is a directive called "#siteFolder". This "tells Fargo where to store your files." - This was all I needed!

  • You see, when you use this directive in your blog it essentially renders the site to the root of the "Dropbox/Apps/Fargo" folder within your Dropbox account. For example, my #siteFolder directive is #siteFolder "blogs/scriven/"

  • When I render my site it renders the output to /Dropbox/Apps/Fargo/blogs/scriven

  • Fantastic, so now I can render my site locally to Dropbox. But how to get this content across to my VPS seamlessly? Read the rest of this how-to to find out! :hand-o-down:

TLDR Overview

  • Setup the Fargo blog to render content to your Dropbox account

  • Synchronise the site from Dropbox to your VPS using dropboxd

  • Configure Apache to make the site(s) available

  • Create a cronjob on the VPS to sync the contents of the Dropbox site content to your Apache content folders

  • Update your DNS records

  • Enjoy your totally self published Fargo blog

Configuring your site to render to Dropbox

  • This step is very straight-forward.

  • Open your outline into Fargo

  • At the bottom of the outline add; Of course you can call your blog what you would like. I'm calling this example, battyblog

    • #siteFolder "blogs/battyblog"
  • NOTE: The reason I added "blogs/" is because I have more than one blog that I publish out of Fargo.

    • blogs/scriven - stream blog

    • blogs/copula - link blog

  • With this folder structure you can have any number of blogs under the "blogs" subdirectory. Of course you can choose any folder you wish. This made made the most sense for my requirements.

  • Once you have some content to render go to the "File" menu and select "Render All Pages"

  • In a few seconds the publisher will create the necessary file structure and the content beneath it. You can check this by going to your Dropbox account and looking under;

    • Apps/Fargo/blogs/
  • As if by magic, under blogs you will see your outline name. Within that will be the content of your blog.

  • The next step is to synchronize your blog content with the VPS, but this requires that the VPS has the Dropbox sync daemon installed and configured. We will tackle this in the next section.

Installing and configuring VPS prerequisites

  • This section is a little more involved, but I will lead you through as coherently as I can.

  • For the following set of instructions I have been using a Debian 7 VM. Other Linux flavours may vary.

  • Whatever distro you use, you will need the following;

    • wget

    • Python 2.x (3.x not currently supported)

    • a web browser*

  • *The web browser can be the one on your machine

  • So lets get going by connecting to the VPS via a root SSH session

  • Once logged in run the following to get the dropboxd software pre-reqs installed. It might be that you already have Python installed on the server.

    • apt-get install wget python
  • Once they are installed let's create a standard user for the purpose of running dropboxd and other Dropbox cli commands later on in this guide

  • In this example I will create a user called "batty"

    • useradd -G sudo -d /home/batty -m -s /bin/bash batty

    • passwd batty

    • chown -R batty:sudo /home/batty

    • usermod -G sudo batty

  • Switch user to batty and change to the home directory

    • su - batty

    • cd ~

Downloading, installing and using the Dropbox CLI via dropbox.py

  • The steps carried out here enabled us to control the dropbox daemon, dropboxd. This step is useful before getting the dropbox daemon because once we download and run dropboxd it will start to download all your files! With the use of the dropbox CLI, dropbox.py, we can control dropboxd. :wink: .. You'll thank me for this step I can assure you!

  • So lets go get the Dropbox CLI

    • wget -O ~/bin/dropbox.py "https://www.dropbox.com/download?dl=packages/dropbox.py"
  • Modify the file to allow execution

    • chmod +x ~/dropbox.py
  • View the help associated with the Dropbox CLI, this will give you an idea of what commands are possible. We will using a few of them shortly.

    • python ~/dropbox.py help
  • But before that, we need to download the Dropbox daemon

Downloading the Dropbox daemon, dropboxd

  • Download the dropbox daemon, dropboxd. In this guide we will be using the 64bit version

    • wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86_64"

    • tar -xvzf dropbox.tar.gz

  • This creates a hidden directory ~/.dropbo:stuck_out_tongue_closed_eyes:ist with an executable called dropboxd

  • We will now run dropboxd and link it with you Dropbox account

  • To run dropboxd, type the following;

    • ~/.dropbo:stuck_out_tongue_closed_eyes:ist/dropboxd
  • You will then see the following output;

    • This client is not linked to any account... Please visit https://www.dropbox.com/cli_link?host_id= to link this machine.
  • Copy the url and paste into a browser. After a few ticks you will see a message telling you that the computer is now linked with your Dropbox account

  • Back at the SSH session you will see that the dropboxd has now connected with your Dropbox account.

  • The result of this is a new directory in the root of the home directory;

    • Dropbox
  • The Dropbox daemon will now be downloading all of your Dropbox folders and files, so we need to stop it.

    • python dropbox.py stop
  • Running the following command will show the status of the Dropbox daemon at any given time

    • python dropbox.py status
  • It should now be stopped;

    • Dropbox daemon stopped
  • Because we only want to synchronise our "Dropbox/Apps/Fargo/blogs" folder, we may need to do some Dropbox folder exclusions. In the case of my personal setup I had to exclude a good number of folders. Below shows an example of how to perform an exclusion;

    • python dropbox.py exclude add Dropbox/
  • To add multiple exclusions in one hit;

    • python dropbox.py exclude add Dropbox/ Dropbox/
  • If you need to list folders within your Dropbox;

    • python dropbox.py list
  • One last thing before you setup your exclusions, you need to start the Dropbox daemon;

    • python dropbox.py start
  • Now go setup your exclusions! When you're done, come back here and we'll carry on... Are you done yet? ... OK let's get on with it.

  • OK, so now we have only the Dropbox/Apps/Fargo/blogs folder in sync with Dropbox

  • You can have a look in the folder by typing;

    • ls ~/Dropbox/Apps/Fargo/blogs
  • Finally, let's make sure that dropboxd starts at every boot;

    • python dropbox.py autostart
  • In the next section we will configure an Apache site to run the blog from.

Installing and configuring Apache to run your blog

  • First off we need to install Apache, if you haven't already got it installed;

    • sudo apt-get install apache2
  • With Apache installed, we need to create a directory to store the blog content, in this example, my blog is called "battyblog"

    • sudo mkdir -p /var/www/battyblog
  • Alter the ownership of this folder to allow our "batty" user to create/delete files/folders

    • sudo chown -R batty:www-data /var/www/battyblog
  • Next we will configure the sites-available to Apache and add configuration for the battyblog site

  • Let's go to the Apache "sites-available" directory

    • cd /etc/apache2/sites-available
  • Create a new file with the name being that of your blog

    • sudo nano battyblog
  • Copy and paste the following into the new file, obviously replacing the domain name with yours

    • <VirtualHost *:80>

    • ServerName battyblog.domain.co.uk

    • DocumentRoot /var/www/battyblog

    • ErrorLog ${APACHE_LOG_DIR}/battyblog_error.log

    • CustomLog ${APACHE_LOG_DIR}/battyblog_access.log combined

    • </VirtualHost>

  • Now we can enable the battyblog site to make it available

    • sudo a2ensite battyblog

    • sudo service apache2 restart

  • If all went to plan, the site should now be available

  • Next stage is to put our Dropbox synchronised blog content into our Apache site, battyblog.

  • NOTE: I haven't covered any aspects of Apache security that can be configured. That is out of the scope of this article! But I suggest you go do some reading on the subject prior to going live.

Syncing the local blog with your Apache content directory

  • Time to take some stock and see where we are.

  • The root of the battyblog site from a local Dropbox perspective is;

    • Dropbox blog location

    • ~/Dropbox/Apps/Fargo/blogs/battyblog

  • The root Web directory of the blog has been set to;

    • Apache blog location

    • /var/www/battyblog

  • Next we need to setup a simple one-way rsync job to synchronise the content from our local Dropbox location to the root of the Apache blog location.

    • ~/Dropbox/Apps/Fargo/blogs -> /var/www/battyblog
  • Open up the crontab

    • crontab -e
  • Copy and paste the following into a blank line of the crontab

    • * * * * * /usr/bin/rsync -avzh --delete /home/scriven/Dropbox/Apps/Fargo/blogs/ /var/www/ < /dev/null 2>&1

    • CTRL o

    • CTRL x

  • This will run an rsync (with delete) every minute. The delete will remove files on the destination directory at every sync. The < /dev/null<&1 ensures that your batty mailbox doesn't get filled up with run messages! You're welcome :smiley:

  • With that final step you should see the content of the blog start to appear in a few moments in the /var/www/battyblog directory.

  • In the next section we will finish off by configuring the DNS for your domain so that the blog appears on the internet.

Configure DNS to allow visits to the self-hosted blog

  • Go to your DNS management and create a new 'A' record that points to the IP address of the VPS we have just been working on.

  • For example; A battyblog.mydomain.co.uk 123.123.123.123

  • NOTE: This change may take minutes, possibly hours.

  • Once the change has occurred visit the site to see the fruits of your labour

    • http://battyblog.mydomain.co.uk
  • Any changes you now make to your blog will be synchronised within a minute or two with your VPS.

  • And this is where this article comes to an end, if you have any questions or comments please contact me @chrisdadswell on Twitter.

VPS provider

Links used for this guide

Credits

  • Dave Winer - Creator of Fargo and other such software snacks(tm) :cheesecake:

Last built: Thu, Sep 4, 2014 at 5:57 PM

By Chris Dadswell, Monday, July 14, 2014 at 1:44 PM. I'm a fixed lunatic super-hawk