Getting Started with WordPress on Cloud Foundry

December 11, 2014 Daniel Mikusa

featured-CF-WPOne of the most popular third party web applications out there is WordPress. Individuals and companies alike both choose the software for its ease of use and capabilities as a blogging platform.

Since WordPress is such a popular piece of software, I wanted to ensure it could be easily deployed on Cloud Foundry. This article walks through the steps required to configure and run WordPress on Cloud Foundry. There is also a short video embedded towards the end. At a high level, here are the steps necessary to do this.

  1. Obtain an account with the Cloud Foundry provider of your choice
  2. Install the cf client on your PC
  3. Setup persistent storage for your WordPress assets
  4. Create a MySQL Service
  5. Configure WordPress
  6. Deploy to Cloud Foundry
  7. Optionally scale the application to meet your performance and redundancy requirements

When complete, you’ll have a setup with one or more instances of WordPress running on top of Cloud Foundry. Each instance of WordPress will utilize a shared MySQL service and the shared file storage that is setup. With multiple instances of WordPress running, Cloud Foundry will automatically balance the application instances across different DEA nodes for additional redundancy. It will also distribute incoming requests to the application across the different instances to help scale the application up to handle greater load.

A high level diagram of this can be seen below.


Prerequisites: Obtaining an Account and the CF Client

There are three things that you’ll need to install WordPress on Cloud Foundry. The first thing is an account account with a Cloud Foundry provider. This could be your own Cloud Foundry installation, one managed by a company like Pivotal Web Services or even just Bosh Lite running on your PC.

The second thing is to have the cf client installed on your computer. If you don’t have this, you can download it here, and you can find documentation here to walk you through the installation process.

The third and final thing you will need is a safe place to store your files. This storage needs to be accessible remotely and it needs to be large enough to hold all your plugins, themes and media files.

For the purposes of this this tutorial, we are going to store our files on an SSH server. I’ve opted for this solution for a few key reasons:

  1. Setting up an SSH server is quick and easy. It has low overhead and resource requirements and is supported on many different operating systems. In fact, you may even have one already available.
  2. Connections to an SSH server are encrypted, and have key validation to confirm that the client is actually talking to the right server. This is helpful to keep our data safe and prevent man-in-the-middle attacks.
  3. Cloud Foundry (since v183) supports FUSE and SSHFS out-of-the-box, so we can easily mount the server as a local filesystem.

These are just my reasons for choosing an SSH server. There are other valid options for file storage, like Amazon S3 or a WebDav server. You will just need to adjust the instructions in this article to work with the particular type of server that you choose.

Once you have created and setup your server, SSH or otherwise, proceed to the next section where we’ll walk through the specific configuration necessary for our WordPress installation.

Server Configuration: Setting Up Persistent Storage

Once your server is running there is only one additional task to ready it for this example. You need to create a dedicated user to receive and store the WordPress files. I suggest creating a dedicated user to limit the access of the account on that machine in the event someone compromises the account.

After you have created the user, you can opt to create a subfolder where you will store the WordPress files. However, this is not a requirement. You can simply put the files in the dedicated user’s home directory.

Application Setup: Configuring WordPress

Now that the server is setup, we can proceed to the setup of the application. First, you will need to clone the WordPress project that I have already created. This will get you an out-of-the-box WordPress installation, that has been adjusted to run on Cloud Foundry. This can be done by running the following two commands in your terminal.

git clone
cd cf-ex-wordpress

After doing this, you might be thinking—hey where are all the files? After all, WordPress is a large project, and there’s only one PHP file, wp-config.php, in this project. This is actually OK. The rest of the WordPress files will be downloaded by the buildpack on the server when your application stages. This is done to save you the time, bandwidth and hassle of uploading those files every time when you push your application to Cloud Foundry. It makes your deploys faster.

Next, we are going to configure WordPress. Like every standard WordPress install, you’ll need to edit wp-config.php and change the secret keys. For security reasons these should be unique for every installation. If you need help generating a good, unique key you can use the secret-key service to generate a random set of keys for you.

That’s it for WordPress configuration. The only other change that would have been necessary was already made for you—grabbing the MySQL database connection information from the VCAP_SERVICES environment variable. If you want to see what this change looks like, you can look at the wp-config.php file, or check out this link.

The next step to configure the application is to create our SSH keys. These will be used by SSHFS to connect to our SSH server and mount the remote directory so that it is available to WordPress. We will use the standard tools available on any Linux, Unix or Cygwin system to create the key. Here are the steps that should be run from the project directory.

mkdir .ssh
chmod 700 .ssh
ssh-keygen -b 4096 -t rsa -N '' -f .ssh/sshfs_rsa
ssh-keyscan -t rsa <ssh-server-ip> > .ssh/known_hosts

If you’re using Windows and do not have Cygwin installed, you can use Putty to generate the keys. The Putty documentation walks through this process here.

Now that we have the key generated, we just need to setup the SSH server to allow us to login with the key and not require a password. This can be done by connecting to your SSH server and adding the contents of the .ssh/ file we just generated to the ~/.ssh/authorized_keys file for the user that you created on the SSH server.

You can then confirm the setup is working correctly with the following command:

ssh -i .ssh/sshfs_rsa -o StrictHostKeyChecking=yes -o
UserKnownHostsFile=.ssh/known_hosts <user>@<ssh-server>

This command should execute without asking you for a password and without prompting you about the authenticity of your SSH server. This is important as SSHFS must be able to mount the remote file system without requiring any user interaction. If you are prompted for either, check the steps above, check that you’ve added the correct public key to the authorized_keys file on your SSH server and that your SSH server is configured to allow key based authentication. Once this is working, proceed onto the next section.

Deploying WordPress to Cloud Foundry

With the steps above complete, we’re now ready to deploy WordPress. This involves using the cf command line utility to create our database service and push the application itself up to the server.

Before we do that, we need to make sure the client is setup correctly. If this is the first time you’ve used the cf utility, you’ll need to complete these steps to point the tool at Cloud Foundry. First, login and select the org and space where you’ll deploy WordPress. These are the commands you need to run to accomplish this.

cf api
cf login
cf target -o <your-org> -s <space-to-use>

This example assumes that you’re going to target Pivotal Web Services. If you’re targeting a different Cloud Foundry installation, simply substitute the API link to your installation in the cf api command.

Once this is complete, or perhaps if you were already logged in, you can proceed to create your database service. We’re going to use a MySQL database, and because our api is Pivotal Web Services, we’re going to use ClearDb as the provider. To create the service, we’ll use this command.

cf create-service cleardb spark mysql-db

This creates a very small, free tier service. If you’re deploying a production or high traffic site, you’ll likely want to start with one of the larger, paid service options from ClearDb or another provider.

With the service created, we are almost ready to deploy. The only remaining task prior to deploying is to inspect and customize the manifest.yml file. To do this, simply open the file in your favorite text editor and adjust as needed.

The section that you will need to complete is the SSHFS configuration, which is done through environment variables, at the bottom. This will need to be completed with the information that is relevant to your SSH server. See the default values for guidance on the values needed.

Also, you can optionally adjust the Cloud Foundry configuration in this file, which comes with sensible defaults. Some of the options you might want to change include the application name (default mywordpress), hostname (default random), memory allocation (default 128M) or the name of the MySQL service (default mysql-db).

After you are satisfied with the options configured in the manifest file, simply run this command to deploy your application to Cloud Foundry.

cf push

That’s it. After it runs, you’ll be able to access WordPress at the URL you configured. If you’re unsure what URL is configured, check the last few lines of the output from cf push, it should contain the specific URL.

Here is a short video to explain:

While this ends our journey to deploy WordPress, it is really just a beginning for you. Because now you’re ready to install some themes, some plugins and begin customizing WordPress.


In this article, we’ve presented the step-by-step instructions for installing your very own WordPress instance on Cloud Foundry. It offers a quick setup, easy scaling of the memory or number of instances you’re running with the cf scale command and an easy way to stay up-to-date with WordPress, PHP and all of the server software required to run WordPress.

Learning More:

About the Author


Distributed Deep Learning on MPP and Hadoop
Distributed Deep Learning on MPP and Hadoop

Deep learning has become a more popular approach to machine learning that has shown to provide significant ...

Data Science and the Internet of Things
Data Science and the Internet of Things

As the Internet of Things (IoT) expands, tremendous amounts of data are being generated by real world devic...

SpringOne 2022

Register Now