test.ical.ly | getting the web by the balls



Deploy your Silex and Twig powered Facebook App using Git onto free Heroku Cloud Hosting

More or less by accident I discovered that Facebook now teams up Heroku a San Francisco based hoster to provide easy hosting environments to Facebook App developers.

So I thought lets try it out and while I’m at it make it run Silex and Twig!

So after you created a new app go to its settings page. There you will find the offer available.

Lets get started!

A full explanation and official announcement of the service can be found on the Facebook Developer Blog.

After you went through the sign-up process your settings page will look like this.

Just copy the Hosting URL as your Website-, Canvas- and/or Page Tab-URL.

Also note that the URL already uses SSL which will be required for all apps from 1st December 2011! And the certificate comes for free as well.

The app on your new hosting environment is a placeholder that demonstrates the most basic things you can do with Facebook. Lets get Silex on there!

After you set up your SSH keys using the Heroku CLI tool you are able to check out your new app using Git.

git clone git@heroku.com:fierce-meadow-9687.git -o heroku

Now you got the code on your server or wherever and you can start editing it to your liking.

So first download the silex.phar file and then create an .htaccess file along with a different index.php.

Please note that you have to use $app->post() instead of $app->get() as Facebook posts an access token to every Canvas App.

Next I followed some instruction from a Russian Silex community page showing how to turn the Twig library into a phar archive (to be honest Chrome translated the page :).

Then I changed my index.php file to this.

Which renders this simple template.

To deploy this code you only have to commit it to the master branch and push it back to the heroku source ($ git push heroku master).

In the documentation you can also find how to run your code manually in your development environment or on a staging server before deploying.

It’s a stupid example I know and of course this is only a start but you can probably see where it could be going from here. The whole setup so far is less than 2mb and as long as you don’t need to scale to a full blown traffic and you keep your quota of the shared database to less than 5mb you will not have to pay a single penny for this!

Funnily I expected this move from Google. To connect Google+ to Google App Engine. But apparently Facebook got there first.

I don’t think this service is suitable for bigger projects but for small apps it’s very convenient I have to say.

· · · · · ·

  • Ivo

    cool, i wasnt aware that heroku supports also PHP,
    somehow i had in mind it was a ruby thing.
    have to check that out

  • @Ivo they provide a few ruby tools so maybe that’s how they started out but they definitely support PHP. :)



Theme Design by devolux.nh2.me