Habari as a Service


When I first heard about OpenShift, I was underwhelmed. Hosting accounts aren’t that hard to find or set up, so the whole Platform-as-a-Service initiative struck me as a solution looking for a problem. But the more I poked around, the more I realized that this was a pretty great offering for developers. I’m not a developer by trade or training, so the obvious utility of PaaS slipped past me at first. As a sysadmin, I’m much more interested in the L and A portions of the LAMP stack than I am in the P. :)

Red Hat has a guide on how to create an OpenShift quickstart for hosted applications. Notably absent from the list of extant quickstart apps was Habari, so I decided to remedy that! Here are my notes for what I did.

First, obviously, I needed to create an OpenShift account. After creating my account, I published my ssh public key to my account. Creating an OpenShift account creates a domain in which your apps will run. My account name is “skippy”, so my OpenShift domain is also “skippy”.

Next I installed the OpenShift client tools:

I tried to create an application:

but got the following error:

The solution is to export the RUBYLIB environment variable to my shell:

I should probably add this to my ~/.bash_profile, but for now I just manually execute this each time I log into my development box.

After that, I was able to create an app:

Here’s the full output from that command:

OpenShift provides some stub files in the /php directory, which we don’t need. Remove them:

I then downloaded a zipfile of the Habari 0.7.1 source code, which is the current stable version. I unzipped the archive and copied the Habari source files to the /php directory of my OpenShift app:

OpenShift deletes the entire contents of your app’s /php directory with every git push, which means that the Habari SQLite database needs to live outside of the /php directory. See OpenShift KB-E1002 for details.

To account for this, we need to build support for this in the Habari config.php. Thankfully, OpenShift provides a number of environment variables that describe the OpenShift application. The $_ENV[‘OPENSHIFT_DATA_DIR’] holds the path to the persistent file storage location for this app. So I created a config.php file in my app’s /php directory with the following:

Habari has long supported an unattended installation process, which makes deploying to OpenShift extremely easy. We can define a $blog_data array in the config.php file which will allow Habari to install itself without human intervention. I added the following to config.php:

Now I’m ready to add the Habari files and my config.php to the OpenShift repository:

I visit http://habari07-skippy.rhcloud.com in my browser and see a ready-to-use Habari blog! I can log in with username “admin” and password “habari”. Success!

But that’s only half the battle: a personal blog running in OpenShift. What I want is to make a template so that anyone can easily deploy a Habari blog on OpenShift.

Following the quickstart instructions, I created a GitHub repository named habari-07-sqlite-quickstart, and added that as a remote repository:

I edited the README file, and copied it to README.md (is that part even necessary?) and then added them to version contol:

Commit these files, and push them up to GitHub:

That’s it! Anyone can now follow the instructions in the README file to easily deploy their own Habari installation on OpenShift!

Once deployed, you can assign custom DNS names to your OpenShift applications with the following command:

Obviously you’ll need to set up the appropriate CNAME record for the alias you define to point to your app’s rhcloud.com address.

I set up another repository for Habari 0.7 using MySQL, but discovered in the process that the Habari automated installation mechanism doesn’t work properly for MySQL. You can still easily deploy Habari using MySQL on OpenShift, but you’ll need to take note of the database details provided to you when you run

When you visit your app’s URL, you’ll get the Habari installation screen, which will require you to plug in the database details. Not a big deal, but not quite as fun as a completely automated installation!

The upcoming release of Habari 0.8 should resolve this problem for MySQL installations, so I’ll make a new OpenShift Quickstart for that once it’s out.

home / about / archive / RSS