Deploying WordPress using AppFog PaaS

I started this post thinking that i will be able to deploy PHP app on cloud just like Grails app via CloudFoundry Paas.  As i learnt, cloudfoundry directly does not support php technology, however,  if run AppFog on top of cloudfoundry this mission – deploy PHP app such as WordPress on cloud  can be accomplished. This post demonstrates an example of exactly that – WordPress deployed in cloud

In order to use AppFog, we have to do one additional step to process described in post ‘Starting with CloudFoundry on  Windows‘. That is we install AppFog

Step 0 – Installing AppFog

Open Command line with Ruby as described in ‘Starting with CloudFoundry on Windows’ post. From Command line run the following command:

>gem install af

This installed AppFog, so you can use it to deploy WordPress

Step 1 – Sign up for account on AppFog.com.

Step 2 – Configure MySql Service

In order our WordPress app to communicate with MySql db in cloud, we have to set cloud environment variables (currently auto-configuration is available only for Node.js under cloudfoundry, however, its possible in near future it will work for other frameworks as well)

So edit wp-config.php as following:

Replace:
define('DB_NAME', 'dbName');
define('DB_USER', 'dbUser');
define('DB_PASSWORD', 'dbPass');
define('DB_HOST', 'margotskapacs.com');

With:

$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"]
define('DB_NAME', $mysql_config["name"]);
define('DB_USER', $mysql_config["user"]);
define('DB_PASSWORD',$mysql_config["password"]);
define('DB_HOST',$mysql_config["hostname"]);
define('DB_PORT',$mysql_config["port"]);

As you see, ‘getenv(“VCAP_SERVICES”) is way to retrieve cloud instance variables that later is passed to your WordPress app

Step 3 – Deploy on Cloud

Open Command line with Ruby and run following commands:

>af login

This will prompt for username and password you registered Step 1

>af push

Given you are in the root directory of your WordPress app. If not, you specify location by ‘ af push –path somePath’

Afterward, follow the default settings and your application will be published under domain name – yourAppName.cloudDomain that you can also find out by logging into appfog.com

Next, how do we import MySql data into our WordPress PHP app residing on Cloud? That’s in next post – Importing MySQL on WordPress Cloud Intance

 

Leave a Reply

Your email address will not be published. Required fields are marked *