Yii On Pagoda Box!

[size="6"]Introduction[/size]

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.

[size="3"]Summary[/size]

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:

[list=1]

[*]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)

[/list]

Now you should have something similar to:




app_dir\

  |-> 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:

[list=1]

[*]Open a terminal / command prompt

[*]cd to the app root directory

[*]git init

[*]git add .

[*]git commit -m "Initial commit"

[/list]

[size="3"]Summary[/size]

Our basic application is created and set up with git.

[size="5"]Boxfile[/size]

[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:




web1:

  name: <your_app_name>

  shared_writable_dirs:

    - /protected/runtime

    - /assets

  document_root: ./

  php_version: 5.3.23

  php_extensions:

    - pdo_mysql

  before_deploy:

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


db1:

  name: <your_db_name>

  type: mysql


global:

  env:

    - PLATFORM: PAGODABOX



[size="3"]Summary[/size]

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

'db'=>(isset($_SERVER["PLATFORM"]) && $_SERVER["PLATFORM"]=="PAGODABOX")?

// Pagoda config

array(

    '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

array(

    '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;

}



[size="3"]Summary[/size]

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.

[list=1]

[*]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

[/list]

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

[size="5"]Cheers![/size]

Hope this helps