Deploy A New Wordpress Blog On AppFog

🦖 This post was published in 2013 and is most likely outdated.

This is a tutorial to get you started with Wordpress on AppFog.

I’m assuming that you already have your environment configured to use AppFog. If not, read my other post on how to deploy a toy PHP application on AppFog.

Get the code

First, download Wordpress

$ wget
$ unzip
$ cd wordpress

Database configuration

The MySQL database will be added and automatically binded to the app as a service, so you don’t know the database parameters (host, user, password) before deploying. However, AppFog will feed the environment variable ` VCAP_SERVICES` on the server with a JSON hash, including the database parameters, like this one:

{"mysql-5.1": [ {
    "credentials": {

You can read a environment variable in PHP with


and decode a JSON string to an associative array with

json_decode($json_string, true)

We need to configure Wordpress to use a MySQL database. Create a configuration file from the example given:

cp wp-config-sample.php wp-config.php

Then in wp-config.php, look for the lines with the database parameters

define('DB_NAME',     'database_name_here');
define('DB_USER',     'username_here');
define('DB_PASSWORD', 'password_here');
define('DB_HOST',     'localhost');

and instead of setting manually those values, we are going to read the environment variable VCAP_SERVICES and feed the parameters directly here, so replace the previous lines by

$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"]);

Deploy to AppFog

$ af push my-blog
Would you like to deploy from the current directory? [Yn]:
Detected a PHP Application, is this correct? [Yn]:
1: AWS US East - Virginia
2: AWS EU West - Ireland
3: AWS Asia SE - Singapore
4: Rackspace AZ 1 - Dallas
5: HP AZ 2 - Las Vegas
Select Infrastructure: 1
Application Deployed URL []:
Memory reservation (128M, 256M, 512M, 1G, 2G) [128M]:
How many instances? [1]:

When asked about creating services to bind to your app, say yes, you need a MySQL database:

Create services to bind to 'my-blog'? [yN]: y
1: mongodb
2: mysql
3: postgresql
4: rabbitmq
5: redis
What kind of service?: 2
Specify the name of the service [mysql-740c4]:
Create another? [yN]:
Would you like to save this configuration? [yN]:
Creating Application: OK
Creating Service [mysql-740c4]: OK
Binding Service [mysql-740c4]: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (22K): OK
Push Status: OK
Staging Application 'my-blog': OK
Starting Application 'my-blog': OK

Web install

Now go to your app, you should be welcomed by Wordpress.

Follow the steps and you should have a running installation of Wordpress on AppFog.

Store uploaded files to S3

The storage on AppFog is not persistent (yet). That means that all the files created on the server may disappear at any time. For Wordpress it can be three things: media uploads (like images of your posts), plugins, and themes. So you have to tell Wordpress to store your static files somewhere else. Here is another post I wrote to Have your WordPress static files on Amazon S3.

Further reading

  1. Wordpress on AppFog official documentation
  2. Dealing with services with the VCAP_SERVICES environment variable.