Yesterday I blogged about Phalcon, the PHP framework written in C. At the end of the post I said I would show you guys how to setup Phalcon on Heroku. After a bit of research and building out a demo app I have it up and running on Heroku. I've simplified the process into 3 steps.

(Optional) Clone my demo application

I built a simple blogging application that utilizes Phalcon's Micro MVC router (think Sinatra), models with relationships, views, autoloading and a few other features. It's very rudimentary containing only a few methods to create posts, view posts and add comments to posts.

$ git clone https://github.com/andruu/Phalcon-on-Heroku.git

Create a new application on Heroku

Make sure that you have the Heroku toolbelt installed and you are logged into your Heroku account. Next you will have to create your app using a custom buildpack. Buildpacks allow you to customize your instance with different modules and allow you to configure it exactly how you want it. Create your new application and commit the code with the command below.

Add the ClearDB MySQL add-on

I was having trouble getting Heroku's built in PostgreSQL to work well with Phalcon but no worries Heroku has a free add-on for MySQL. Run the following command to setup your MySQL database.

$ heroku addons:add cleardb:ignite

Setup the database

Now you just have to create your tables. Your MySQL connection information is stored on Heroku as an environment variable which is already detected if you are using the demo app provided. You will need to setup the tables before you can use your app. You can get the credentials by running the following command.

$ heroku config

Look for the CLEARDB_DATABASE_URL variable. You can now use this to login to MySQL via the command line or your favourite GUI. Once logged in run the following SQL to create your tables.