Shim your PHP Fog env_vars into AppFog
The below code is what I use to shim AppFog VCAP_SERVICES into PHP Fog Environmental Variables (this only works with PHP apps). To accomplish this, Follow these steps:
Create phpfog.php file and place it in the same directory as your frameworks database configuration file.
Paste this code into the phpfog.php file:
<?php
$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
putenv('MYSQL_DB_HOST=' . $mysql_config["hostname"] . ':' . $mysql_config["port"] );
putenv('MYSQL_USERNAME='. $mysql_config["user"]);
putenv('MYSQL_PASSWORD='. $mysql_config["password"]);
putenv('MYSQL_DB_NAME='. $mysql_config["name"]);
In your configuration file add this line right below the "<?php":
include 'phpfog.php';
This will shim the VCAP_SERVICES environmental variable in AppFog and other Cloud Foundry distributions into standard Environmental Variables.
Written by Richard Howard
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#