Static Files on OpenShift and WordPress

This blog just recently moved from PagodaBox to OpenShift due to some server issues. With a new infrastructure, there were changes in my WordPress installation where most of my static files stopped working. Reading the incomplete documentation didn’t help but I figured it out by reading some deployment scripts.

The OpenShift Structure

OpenShift has some weird infrastructure where you select the type of application you are trying to deploy and you follow some strict rules so things would work. It is not a typical cloud hosting. You can think of it as PagodaBox, but supports more languages, like Ruby or Python.

In a WordPress type of application, OpenShift provides the WordPress application, which you provide the data, plugins, themes and some other files. After deploying the data, themes and plugins ((you figure it out), I’ve found out that my ads and static images are not loading.

Deploy Script

I’ve found out that you can add your static files and other stuff to a deploy script and commit it to GIT.

The file is at .openshift/action_hooks/deploy.

I wanted to deploy files at BASEURL/ads and BASEURL/static_uploads. This resides at my project root directory but does not resolved once deployed in OpenShift.

I just added the following lines, right after the .htaccess line.

# This is included in basic OpenShift WordPress stock

# Use repository htaccess if exists 
if [  -f ${OPENSHIFT_REPO_DIR}.openshift/config/.htaccess ]; then
  cp -f ${OPENSHIFT_REPO_DIR}.openshift/config/.htaccess ${dest_dir}/.htaccess

# I added these

# Add the ads templates
if [  -d ${OPENSHIFT_REPO_DIR}ads ]; then
  cp -rf ${OPENSHIFT_REPO_DIR}ads ${dest_dir}/ads

# Add the static uploads dir
if [  -d ${OPENSHIFT_REPO_DIR}static-uploads ]; then
  cp -rf ${OPENSHIFT_REPO_DIR}static-uploads ${dest_dir}/static-uploads

After committing and pushing the code, ads and static files are now working.

Sorry for the rush post.

No Comments

Leave a reply

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