Last Updated: February 25, 2016
·
846
· sjimenez77

Integrate Symfony2 in AppFog

Some AppFog platforms are PHP framework ready. For these ones, you can create a new config file in order to detect the platform database parameters for your instance when deploying your Symfony2 web app and then integrate it as resource in the config.yml file imports section.

// Parameters for deployment in AppFog
$vcap = getenv("VCAP_SERVICES");

if ($vcap)
{
    // Environment variable VCAP_SERVICES exists
    $services_json = json_decode($vcap, true);
    $mysql_config = $services_json["mysql-5.1"][0]["credentials"];

    // Set Symfony2 parameters
    $this->container->setParameter('database_host', $mysql_config["host"]);
    $this->container->setParameter('database_name', $mysql_config["name"]);
    $this->container->setParameter('database_user', $mysql_config["user"]);
    $this->container->setParameter('database_password', $mysql_config["password"]);
}

If VCAP_SERVICES environment varible exists we change every database parameter for our app instance. If it does not exist the default database parameters in parameters.yml will be used.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside