Fever on Heroku

So yesterday brought the sad news that Google Reader is being killed off. C’est la vie it seems, given it was a Google product. In my search for an alternative I rediscovered Fever and decided to see if I could run it up for free on Heroku. Onwards…

Unfortunately there were more issues than I first thought with the licensing built into Fever and getting it to play nice in a filesystem-less environment like Heroku. The below steps will work just fine, however you will be left having to re-activate Fever every time your dyno goes away (thus blowing away the in-memory downloaded activation). Sadface.

Personally I think the news about Reader is quite sad, as I would quite happily have paid for it as a service. In fact I like RSS so much that I actually shelled out the $30 for Fever when it first came out years ago (I was also pretty massive Shaun Inman fanboy if I’m being honest).

I ended up setting Fever aside because screw having to manage self-hosting for PHP and MySQL, right?

If you’re new to Fever I recommend going and checking it out, but also reading the post in response to the Google Reader announcement by Fevers author, Shaun, for a good list of what Fever is and isn’t.

Enough jibba-jabba!

Let’s turn up the heat!

OK, so I’m going to go ahead and just assume that if you’re reading this then you are already probably familiar with Heroku and already have an account and their toolchain already set up on your machine (for the sake of not having a bad time I’m also going to assume you are not using Windows, because LOL).

There are unfortunately several extra steps to getting the Fever app set up on Heroku. The design of Fever’s setup is such that it actually downloads itself during setup. Weird stuff. I guess this is some sort of code obfuscation(?), but all of this code can be acquired prior to entering your activation anyway…

Anyway, this all creates something of an issue when you are looking to deploy to an environment that doesn’t have a writable file-system…like Heroku.

The way to get around this is to go through the setup process right up until activation on your local machine—at which point the you have all the app code—then just commit this code and push that up to Heroku.

If you just commit the bootstrapping stuff and then run the setup on Heroku the app will run just fine…right up until the dyno is recycled, at which point the code disappears, your app breaks.

Local stuff

First up we need to make a local repo for Fever to live in and for us to deploy to Heroku from.

Let’s open Terminal and mash some keys!

mkdir fever
cd fever
git init .

…while we’re at it let’s create a new Heroku app!

Running PHP on Heroku is not officially supported, but it is easy, thanks to iphoting’s awesome PHP + nginx, etc… custom buildpack.

heroku create -s cedar -b git://github.com/iphoting/heroku-buildpack-php-tyler.git

…and now we’ll grab the Fever bootstrap code and commit it. We also need to add an empty index.php file to the root of our app. This is required as this is how Heroku will identify it as being a PHP deployment…

wget http://feedafever.com/gateway/public/fever.zip
unzip fever.zip -d . && rm fever.zip
touch index.php
echo "<?php header(\"Location: /fever/\"); ?>" > index.php
git add -A .
git commit -m "Added Fever bootstrap code, Heroku index.php"

Next up you’ll need to load up the app locally in your browser (you will need a way of running PHP/MySQL locally, just grab MAMP free), and jump over to /fever/boot.php.

Jump through all the setup steps until you get to the database setup stage. Throw in your local MySQL details (you’ll need to create a temporary DB, don’t worry we’ll delete it all later).

At each stage here the boot script is downloading more of the actual fever app, once you get to the section where it asks you to activate Fever you have all the core code needed to run the app.

The last thing we need to so is throw in the actual settings for our Heroku MySQL database and replace out the local settings we used when running setup.

Before we can do that though we need to add a MySQL addon to our app:

heroku addons:add cleardb:ignite

Once that’s done, we can grab our DB config details by running the following:

heroku config | grep CLEARDB_DATABASE_URL | cut -d " " -f2 | php -r '$conn=""; $in=fopen("php://stdin", "r"); while(!feof($in)){ $conn=$conn . fgets($in, 4096); } print_r(parse_url($conn));'

Note that path is the database name, just leave out the / at the start.

You then need to add these credentials to ./fever/firewall/receipt_db.php.

Once this is all done:

git add -A .
git commit -m "Fever setup complete"

…and deploy!

git push heroku master

Once the post-recieve hook has finished up (it will do a bunch of stuff to pull down binaries for our buildpack) you should be able to load up the app:

heroku open

Awesome—you should now have Fever up and running! You just scored a very capable RSS reader for the worth-while one-off cost of $30m and set up free managed hosting for it for eternity (or until Google buys Heroku and then shuts them down ;).

Get reading!

Bonus Round!

By default Fever will refresh feeds on page load, however they do provide a method for triggering a refresh via a web-hook, which you can hit from a cron task.

If this sounds like something you might be interested in then install and configure the Heroku scheduler addon:

heroku addons:add scheduler:standard
heroku addons:open scheduler

You’ll want to set the command field to:

curl -L -s http://YOUR_HEROKU_APP/fever/?refresh

Save and you’re done.