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:

$ sudo gem install rhc

I tried to create an application:

$ cd ~/code
$ rhc-create-app -a habari07 -t php-5.3 -l skippy@skippy.net
but got the following error:
/var/lib/gems/1.8/gems/rhc-0.81.14/bin/rhc-create-app:24:in `require’: no such file to load – rhc-common (LoadError)
    from /var/lib/gems/1.8/gems/rhc-0.81.14/bin/rhc-create-app:24

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

$ export RUBYLIB=/var/lib/gems/1.8/gems/rhc-0.81.14/lib
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:

$ rhc-create-app -a habari07 -t php-5.3 -l skippy@skippy.net
Here’s the full output from that command:

Found a bug? Post to the forum and we’ll get right on it. IRC: #openshift on freenode Forums: https://www.redhat.com/openshift/forums

Attempting to create remote application space: habari07 Now your new domain name is being propagated worldwide (this might take a minute)… Pulling new repo down Warning: Permanently added the RSA host key for IP address ‘’ to the list of known hosts. Confirming application ‘habari07’ is available Attempt # 1

Success! Your application ‘habari07’ is now published here:


The remote repository is located here:


To make changes to ‘habari07’, commit to habari07/.

Successfully created application: habari07

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

$ rm -rf habari07/php/*

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:

$ cp -av habari-0.7.1/* habari07/php

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:


Config::set( ‘db_connection’, array( ‘connection_string’=>“sqlite:$path/habari.db”, ‘username’=>“, ‘password’=>“, ‘prefix’=>” ));

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:

$blog_data = array( ‘blog_title’ => ‘Habari’,
    ‘admin_username’ => ‘admin’,
    ‘admin_pass1’ => ‘habari’,
    ‘admin_pass2’ => ‘habari’,
    ‘admin_email’ => ‘CHANGE@ME’,

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

$ cd habari07/php<
$ git add .
$ git commit -a -m ‘initial Habari commit’
$ git push

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:

$ cd ~/code/habari07
$ git remote add github https://skpy@github.com/skpy/habari-07-sqlite-quickstart.git

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

$ git add .

Commit these files, and push them up to GitHub:

$ git commit -a -m ‘adding README’
$ git push -u github master

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:

$ rhc-ctl-app -a habari07 -c add-alias –alias openshift.skippy.net -l skippy@skippy.net
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

rhc-ctl-app -a $APPNAME -e add-mysql-5.1 -l $USERNAME
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 / posts / notes / RSS