Phalcon the PHP framework written in C

Over the past few years the PHP community has matured and evolved immensely The language itself ...

Polytalk Ruby Gem updated

I just pushed some changes to the Polytalk Ruby Gem to allow symbols to be used as arguments. Als...

0
Thursday, December 6, 2012
Setting up Phalcon on Heroku

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.

$ heroku create phalcon --buildpack git://github.com/elct9620/heroku-buildpacks-php-with-phalcon.git
$ git push heroku

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.

SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
--  Table structure for `comments`
-- ----------------------------
DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `comment` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8;

-- ----------------------------
--  Table structure for `posts`
-- ----------------------------
DROP TABLE IF EXISTS `posts`;
CREATE TABLE `posts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL,
  `body` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8;

SET FOREIGN_KEY_CHECKS = 1;

That's it you should now be up and running. Test out your application by running.

$ heroku open
Tweet this post if you found it useful

Related Posts

Phalcon the PHP framework written in C

Wednesday, December 5, 2012  ·   4

Over the past few years the PHP community has matured and evolved immensely The lang... (continued)

Rails 3 full page caching on Heroku

Wednesday, November 28, 2012  ·   2

Recently I implemented full page caching on this blog. Not because of the insane amou... (continued)

Introducing Polytalk. A simple protocol which allows communication between different languages via TCP.

Monday, November 26, 2012  ·   0

Polytalk is my latest open source project. I developed it out of the need to communic... (continued)

0 Comments

Comment successfully added. View comment.×

Comments are now closed for this article.