Yii On Pagoda Box!


Pagoda Box (pagodabox.com) is yet another PaaS offering. Currently only supporting PHP. They define them self as "An Object Oriented Hosting Framework".

That said, in my opinion, I have found them to be painless to use, well documented, very capable and as it turns out, a perfect playground for testing apps (read => free).

Initially had some trouble deploying my first app. So thought I will share with you what I have learned since then. This will only be a basic intro.

[size="5"]Requirements & Constraints[/size]

To follow this walkthrough will will have to use:

Apparently as this is my first contribution to yiiframework.com, I am to much of a sausage to create a wiki article or add links to posts. So please bear with me.

[size="5"]Create a new application[/size]

Let’s assume that you already have an account on Pagoda Box.

[size="3"]Step 1[/size]

Head on over to your dashboard and click the "New Application" button

[size="3"]Step 2[/size]

You will be presented with 3 options, select "Empty Repo" and enter a name for your application.

[size="3"]Step 3[/size]

Since the app is empty at this stage you will see a "Choose a Deployment Method" screen.


So now we have an application on Pagoda Box with nothing on it, yet.

[size="5"]Create your yii app[/size]

[size="3"]Step 1[/size]

This part is well documented under the Yii documentation, but just to sum up:


[*]Create an empty folder

[*]Copy the "framework" folder into it

[*]Use the webapp command to initialise the app (eg. php framework\yiic.php webapp . git)


Now you should have something similar to:


  |-> assets\

  |-> css\

  |-> framework\

  |-> images\

  |-> protected\

  |-> themes\

  |-> index.php

  |-> index-test.php

  • Note that the framework folder is inside the app directory

[size="3"]Step 2[/size]

Initialise the app as a git repo:


[*]Open a terminal / command prompt

[*]cd to the app root directory

[*]git init

[*]git add .

[*]git commit -m "Initial commit"



Our basic application is created and set up with git.


[size="3"]Step 1[/size]

Create a file with with the name "Boxfile" - Case sensitive & no file extention

[size="3"]Step 2[/size]

Add the following to the file:


  name: <your_app_name>


    - /protected/runtime

    - /assets

  document_root: ./

  php_version: 5.3.23


    - pdo_mysql


    - "php protected/yiic.php migrate up --interactive=0"


  name: <your_db_name>

  type: mysql





Well, that was easy. Although the astute among you would have realised that the basic yii app uses a generic sqlite database, yet we defined a mysql DB in our box file…

[size="5"]MySQL-fy your app[/size]

[size="3"]Step 1[/size]

Go to your main.php config and change the db config to the following:

// Select database config based on environtment variable


// Pagoda config


    'connectionString' => 'mysql:host='.$_SERVER["DB1_HOST"].';port='.$_SERVER["DB1_PORT"].';dbname='.$_SERVER["DB1_NAME"],

    'emulatePrepare' => true,

    'username' => $_SERVER["DB1_USER"],

    'password' => $_SERVER["DB1_PASS"],

    'charset' => 'utf8',


// Local config


    'connectionString' => 'mysql:host=localhost;dbname=yiistarter',

    'emulatePrepare' => true,

    'username' => 'root',

    'password' => '',

    'charset' => 'utf8',


Now do the same for your console.php db config.

[size="3"]Step 2[/size]

Now we have to create a migration (see docs for more info). Add the following to create a test table. This will function as a test of migration functionality & database setup.

public function up() {

    $this->createTable('test', array(

        'test_id INT NOT NULL AUTO_INCREMENT',

        'test_column VARCHAR(45) NULL',

        'PRIMARY KEY (test_id)',


    return true;


public function down() {

    echo "m130830_113125_test_table does not support migration down.\n";

    return false;



So now our app "uses" MySQL. Any further database changes (done via migrations) will be implemented on Pagoda Box when deploying as well. (You may recall the "before_deploy" hook is set up to do migrations)

[size="5"]Engage thrusters, Deploy![/size]

Add your your Pagoda Box application repository as a remote to the git repo.


[*]Login to Pagoda Box

[*]You should see your app on your dashboard, go ahead on open it

[*]The "Choose a Deployment Method" screen will be displayed

[*]Run the command "git remote add pagoda…" - this will add the Pagoda Box git repo as a remote.

[*]Now to deploy, run: git push pagoda --all


Pagoda Box should be outputting a bunch of info statements.

Near the end of the statements you will see "INFRASTRUCTURE GOING LIVE" if it deployed successfully, otherwise you will see ":: aborting!" if it failed


Hope this helps