Deploying Wordpress to Openshift

Even though I have moved to Jekyll for this blog, Wordpress remains an extremely powerful and user-friendly blogging engine. If it weren't for its PHP nature, I'd probably still be using it. But I digress. While most of my in-development Node apps run on Heroku, for my latest Wordpress project I decided to give OpenShift a try. (My decision may have been influenced by working with ex-Makara and ex-RedHat folks at [StrongLoop][ls], but they didn't solicit this post.)

OpenShift provides an example Wordpress project this method relies heavily on, but I wanted to diverge from this method by managing the Wordpress code as a separate Git repository. That is, the OpenShift app server is the only remote for any OpenShift-specific code, and GitHub provides the remote for everything else: Wordpress core, plugins, themes, etc.

Steps

Assuming your app is named "awesome_blog" (replace all occurrences otherwise):

  1. Gather the required accounts for OpenShift and GitHub.
  2. Download git (Instructions) and rhc (Instructions).
  3. cd to your favorite projects directory.
  4. Log into your OpenShift account: rhc setup.
  5. Create your new app: rhc create-app awesome_blog php-5.3.
  6. In the new awesome_blog directory, remove the existing php directory:
    1. pushd awesome_blog
    2. git rm -rf php
    3. git commit -m "Remove sample PHP code."
    4. popd
  7. Create a new repo on GitHub (Link). These instructions assume you called it awesome_blog. Take note of the Git remote URL GitHub presented you with upon completion, as you'll need that in later steps.
  8. Download Wordpress: wget http://wordpress.org/latest.tar.gz.
  9. Untar Wordpress: tar -zxvf latest.tar.gz.
  10. In the new wordpress directory, add GitHub as the remote and push Wordpress (replace $URL with the remote URL from before):
    1. pushd wordpress
    2. git init
    3. git remote add origin $URL
    4. git add .
    5. git commit -m "Wordpress 3.6"
    6. popd
  11. Link the two together (For best results, use the HTTPS GitHub URL [e.g. https://github.com/schoonology/mi] instead of the SSH URL):
    1. pushd awesome_blog
    2. git submodule init
    3. git submodule add $URL php
    4. git add .
    5. git commit -m "Link Wordpress source."
    6. popd
  12. Now for the special sauce from OpenShift's example.
    1. pushd awesome_blog/.openshift
    2. pushd action_hooks
    3. wget https://raw.github.com/openshift/wordpress-example/master/.openshift/action_hooks/deploy
    4. chmod +x deploy
    5. popd
    6. wget https://raw.github.com/openshift/wordpress-example/master/.openshift/openshift.inc
    7. wget https://raw.github.com/openshift/wordpress-example/master/.openshift/php/wp-config.php
    8. popd
  13. This is close, but we need two more changes:
    1. We want to manage all plugins and themes through GitHub. Remove lines (roughly) 11-17 and 24-26 of ./awesome_blog/.openshift/action_hooks/deploy.
    2. We need to get that sweet, sweet wp-config.php file into the php directory instead of in .openshift. Add the following below what used to be line 27 (the only ln -sf line left): cp $OPENSHIFT_REPO_DIR/.openshift/wp-config.php $OPENSHIFT_REPO_DIR/php/wp-config.php
  14. Since this setup requires MySQL, let's add it to our app before the final push:
    1. rhc cartridge add -a awesome_blog -c mysql-5.1
  15. That should do it! Just commit those last changes, push, and enjoy!
    1. `pushd awesome_blog
    2. git add .
    3. git commit -m "Add action_hooks and OpenShift Wordpress Magic(tm)."
    4. git push origin HEAD
    5. popd

Notes

Thanks to the OpenShift guys for solving all the hard problems with Wordpress on their system. It may seem obvious to us onlookers, but it's a small detail in the giant problem of building and managing a PaaS solution successfully. Thanks for the attention paid to the details.

These intructions were run on Ubuntu 12.04 LTS. YMMV.

More Posts