Are you ready to build an awesome Facebook Application and host it on OpenShift? Good, then let’s get started!
There are a few steps you need to complete before you can begin building Facebook Applications on OpenShift, lets go ahead and get them out of the way now.
Get an OpenShift Account
First you need to sign up for a free account on OpenShift.com so you have a place to host your application. Then install the OpenShift rhc client tools (or you can use the web console). If you need help installing the rhc client tools, please see this article.
Become a Facebook Developer
Next you need to sign up for an account on Facebook and then enroll in the developer program. Note that you will have to verify your account by adding a credit card number or phone number before you can build Facebook applications. Go ahead and go complete those two steps and I’ll wait for you here.
Get Down to Business
Now that you have your OpenShift.com account and your Facebook Developer accounts, we can get down to business.
We are going to break this process down into three easy steps.
- Create your OpenShift gear which will house the web pages and database that we are going to use for our Facebook Application.
- Setup our application in the Facebook Developer Portal and connect it to your gear.
- Write an awesome application that everyone on Facebook will want to use.
Step 1 – Creating your OpenShift gear
If you don’t already have the OpenShift rhc client tools installed, please see the link at the top of this blog post about how to get them installed.
We are going to create one gear that will house our web pages (using PHP). We do this by issuing the following command:
rhc app create openshiftquiz php-5.4
If you see some text that looks like this:
The authenticity of host 'openshiftquiz-facebookapp.rhcloud.com (126.96.36.199)' can't be established. RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx. Are you sure you want to continue connecting (yes/no)?
Just type yes and hit enter.
You will see something like the below which will show you that your application was created, and showing your database credentials.
Application Options ------------------- Domain: facebookapp Cartridges: php-5.3 Gear Size: default Scaling: no Creating application 'openshiftquiz' ... done Waiting for your DNS name to be available ... done Creating application 'openshiftquiz' ... done Waiting for your DNS name to be available ... done Cloning into 'openshiftquiz'... Warning: Permanently added the RSA host key for IP address '188.8.131.52' to the list of known hosts. Checking connectivity... done Your application 'openshiftquiz' is now available. URL: http://openshiftquiz-facebookapp.rhcloud.com/ SSH to: firstname.lastname@example.org Git remote: ssh://email@example.com/~/git/openshiftquiz.git/ Run 'rhc show-app openshiftquiz' for more details about your app.
Step 2 – Creating your Facebook Application and connecting it to your OpenShift gear
Now that your OpenShift gear has been created, and the basic code has been cloned to your local computer, lets setup your Facebook application and connect it to your gear.
First you need to visit the Facebook Developer Portal, then click on “Apps” on the top menu, and then “Create a New App”
Next you will need to choose a Display Name and Namespace for your application. The namespace is part of the URL that people will see when using your application. You will also need to choose a Category and Sub-Category for your application.
You will then be shown some information about your application that has been created such as your App ID, App Secret, etc. Click on the “Settings” button on the left menu to finish setting up your application.
After you are on the settings page, you will need to click the “Add Platform” button so that we can link this application to our OpenShift gear.
You will get another screen with a whole bunch of application types listed. For this demo we are going to choose the “App on Facebook” type by clicking on it in the top left corner.
Now it’s finally time to link this application to our OpenShift gear. Go ahead and enter the URL of the gear that you created in step one in the “Canvas URL” text field, and the same URL in the Secure Canvas URL field, except use https instead of http in the second box as shown in the below screenshot. Make note of the “Canvas Page” URL at the top of this page, this is the URL that users will use to visit your application, and the URL you can use to test your application in the next step.
Once you have clicked the “Save Changes” button at the bottom right of the page, you can visit the “Canvas Page” URL that you noted in one of the previous steps and see the “Welcome to your PHP application on OpenShift page. Now we are finished connecting our Facebook application to our OpenShift gear.
Now that we have our Facebook Application hooked up to our OpenShift gear, let’s move on to the fun part.
Next time we’ll show you how to get your PHP application talking to Facebook in “Developing Facebook Applications on OpenShift: Launch Your App“.