Love Fuel?    Donate

Thoughts, ideas, random notes, ramblings...

Anything about PHP in general, and FuelPHP in particular. Sometimes serious, sometimes with a big wink. But always with a message. Do you have an opinion about an article? Don't forget to comment!

A few weeks back our site was down for most of the day, which sucked. The start of the problem was a failed deploy of an update to PyroCMS.  Then all hell broke loose.  We basically decided to start from scratch with a fresh install of PyroCMS v2.0 beta.  Since we were starting fresh we also took the opportunity to make a hosting platform move as well.

Phil and I (Dan) were both involved in some early beta testing of Pagoda Box.  I am not going to lie, it was a little rough, like any beta usually is, but we saw a lot of potential.  On Nov. 1st, they completed their transition to a new infrastructure, and simply put, it is awesome.  After testing out the new infrastructure I decided that I wanted to make the switch.

Like most of it's competitors, you can quickly create new apps and add or remove instances as needed.  However, unlike most (or all) of their competitors you have access to writable storage which is accessible across all app instances.  This is really important for things like upload directories, caches, etc.  I could go on for ever about all of the options they provide, but instead, I will walk you through getting a FuelPHP app up and running on Pagoda Box.

Before I get to that, let me take a second to say that they have the best customer service of any hosting company I have ever used (and I have used a lot).  I would go so far as to say that they are better and more responsive than RackSpace (to be fair, RS is much larger though).

Note: I am not going to walk you through the app creation process as their site has very good docs on this.

Create a Boxfile

A Boxfile is how you configure most of the options for your app.  There are a ton of options you can choose from, most of which I won't cover here, but you can see them all here.

First, create a file named "Boxfile" (case-sensative, no extension) in your root diretory.  That file should contain something like the following:

web1:
  shared_writable_dirs:
    - /fuel/app/cache
    - /fuel/app/logs
    - /fuel/app/tmp

  document_root: /public
  php_version: 5.3.8
  php_extensions:
    - pdo_mysql
    - gd
    - apc
    - curl
    - mbstring

  php_error_reporting: 'E_ALL'
  php_display_errors: On
  php_short_open_tag: Off
  php_date_timezone: US/Pacific

db1:
  name: your_db_name
  type: mysql

You can modify it to include any of the extensions your app needs obviously. The important part is just setting the document_root correctly and the shared writable directories.

Database Setup

In the Boxfile you will notice the 'db1' section.  This will tell Pagoda Box to make sure you have a database with the given name and type when you deploy.  This also tells it to automatically create some Environment Variables for you to use.  They are as follows:

$_SERVER['DB1_HOST']
$_SERVER['DB1_PORT']
$_SERVER['DB1_NAME']
$_SERVER['DB1_USER']
$_SERVER['DB1_PASS']

We wont worry about the port one for now (it runs on the standard MySQL port of 3306). So, before you even deploy, you can count on these variables being there. So, you simply need to update your production database settings (assuming the v1.1 default of app/config/production/db.php):

<?php
/**
 * The production database settings.
 */

return array(
    'default' => array(
        'connection'  => array(
            'dsn'        => 'mysql:host='.$_SERVER['DB1_HOST'].';dbname='.$_SERVER['DB1_NAME'],
            'username'   => $_SERVER['DB1_USER'],
            'password'   => $_SERVER['DB1_PASS'],
        ),
    ),
);

Save that file and you never have to update it again.

Setting your Environment

FuelPHP will auto-set your current environment by looking for an Environment Variable by the name of FUEL_ENV (all upper-case).  Pagoda Box has a really simple interface for adding them.  So, you first need to deploy your app, then go into the dashboard and add a new Env. Variable.  You want to set the variable to production (NOTE: This is case-sensitive, and must be all lower case).

Your app should now be up and running.

Conclusion

Pagoda Box is a force to be reckoned with in the PHP PaaS world.  We support them 100%, and wish them nothing but the best.