Your first OpenShift Facebook application

Facebook [feys-boo k] - "to communicate with (a person) or search for information about (a person) by using Facebook" (dictionary.com)

They didn't have definition of OpenShift, but since you are reading this you probably know what it is. So you want to develop an application for Facebook and you wonder where to host it? That's one thing OpenShift can help you with.

The steps to create a simple Facebook application on OpenShift are very easy. I created a small "hello world" application with PHP to show how it's done.

Create OpenShift application

Go to OpenShift Online and create new PHP 5.3 application. I've used "facebooktest1" as the name here.

Clone the code to your laptop and download the Facebook PHP API v3 from here: https://github.com/facebook/facebook-php-sdk and copy the contents of the extracted src directory into your Openshift application:

git clone ssh://...
cd facebooktest1
cp -r ~/Downloads/facebook-php-sdk-master/src facebook

Create Facebook application

At https://developers.facebook.com create your Facebook application and add platform Facebook Canvas into it. Use the application URL from OpenShift as Canvas URL.

In this example I've used openshifttest1 as the application name.

Configure OpenShift environment variables

You'll need to set some environment variables in order to avoid having to insert Facebook App ID and App Secret into your source code. Namespace is your OpenShift domain name and application name is the OpenShift application name.

rhc set-env FBAPPID=365476396940042 --namespace twillber --app facebooktest1
rhc set-env FBAPPSECRET=hidden --namespace twillber --app facebooktest1

rhc set-env FBNAMESPACE=twillber-openshift --namespace twillber --app facebooktest1

Write the PHP application

Here is a very simple index.php just to show your Facebook name and user ID:

You can fetch the example code from here: http://people.redhat.com/~twillber/files/openshift/index.php.txt

Commit your code

At the end your directory structure should look like this:

[facebooktest1]$ tree
|-- facebook
|   |-- base_facebook.php
|   |-- facebook.php
|   `-- fb_ca_chain_bundle.crt
`-- index.php

1 directory, 4 files

Time to add the files and commit everything to OpenShift Online:

git add --all .
git commit -am 'created cool app'
git push

Demo time!

Browse to your application and enjoy your hard work: https://apps.facebook.com/twillber-openshift/