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):
- Gather the required accounts for OpenShift and GitHub.
- Download
git
(Instructions) andrhc
(Instructions). cd
to your favorite projects directory.- Log into your OpenShift account:
rhc setup
. - Create your new app:
rhc create-app awesome_blog php-5.3
. - In the new
awesome_blog
directory, remove the existingphp
directory:pushd awesome_blog
git rm -rf php
git commit -m "Remove sample PHP code."
popd
- 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. - Download Wordpress:
wget http://wordpress.org/latest.tar.gz
. - Untar Wordpress:
tar -zxvf latest.tar.gz
. - In the new
wordpress
directory, add GitHub as the remote and push Wordpress (replace $URL with the remote URL from before):pushd wordpress
git init
git remote add origin $URL
git add .
git commit -m "Wordpress 3.6"
popd
- Link the two together (For best results, use the HTTPS GitHub URL [e.g. https://github.com/schoonology/mi] instead of the SSH URL):
pushd awesome_blog
git submodule init
git submodule add $URL php
git add .
git commit -m "Link Wordpress source."
popd
- Now for the special sauce from OpenShift's example.
pushd awesome_blog/.openshift
pushd action_hooks
wget https://raw.github.com/openshift/wordpress-example/master/.openshift/action_hooks/deploy
chmod +x deploy
popd
wget https://raw.github.com/openshift/wordpress-example/master/.openshift/openshift.inc
wget https://raw.github.com/openshift/wordpress-example/master/.openshift/php/wp-config.php
popd
- This is close, but we need two more changes:
- 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
. - We need to get that sweet, sweet
wp-config.php
file into thephp
directory instead of in.openshift
. Add the following below what used to be line 27 (the onlyln -sf
line left):cp $OPENSHIFT_REPO_DIR/.openshift/wp-config.php $OPENSHIFT_REPO_DIR/php/wp-config.php
- We want to manage all plugins and themes through GitHub. Remove lines (roughly) 11-17 and 24-26 of
- Since this setup requires MySQL, let's add it to our app before the final push:
rhc cartridge add -a awesome_blog -c mysql-5.1
- That should do it! Just commit those last changes, push, and enjoy!
- `pushd awesome_blog
git add .
git commit -m "Add action_hooks and OpenShift Wordpress Magic(tm)."
git push origin HEAD
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.
21st of August, 2013