12 Tips for Hosting WordPress on OpenShift

WordPress is the most popular QuickStart on OpenShift Hub. Here are some tips to make the most of it!

Tip 1: Use PHP 5.4 and MySQL 5.5

This is an easy win if you’re on PHP 5.3 or MySQL 5.1. The newer versions of PHP and MySQL came with bug fixes, new features, and performance enhancements.

For new deployments, make sure you use PHP 5.4 and MySQL 5.5. Don’t get started yet! We began here to lead into tip #2.

Tip 2: Move your Database to a Separate Gear

Another easy win. It’s not immediately obvious how to do this in OpenShift Online, but it’s very easy once you’re aware it’s possible.

The solution: deploy WordPress as a ‘scalable’ application with PHP set to scale to a maximum of 1 gear. OpenShift will run PHP on one gear and MySQL on a separate gear. Your database will have a separate set of resources (memory, storage, and CPU).

For new deployments from the web console, select the option to “Scale with web traffic”:

Enable scaling to add a database gear

IMPORTANT: Make sure you update your scaling settings after your app is created! Click on your app, then click the link under ‘Scales’ to adjust your scaling settings. Set PHP to scale to a max of 1 gear.

Do not scale beyond one gear

For new deployments from the command line:

$ rhc create-app <app name> php-5.4 mysql-5.5 --from-code=https://github.com/openshift/wordpress-example -s
$ rhc cartridge scale php -a <app name> --min 1 --max 1

Tip 3: Upgrade to Bronze to Disable Idling (it’s free)

If you live in the US, Canada, Europe, or Israel and you haven’t upgraded to the OpenShift Bronze Plan you’re missing out on a completely free upgrade. ‘Upgrading’ to the OpenShift Online Bronze Plan disables application idling for any gears running on your account. And, I can’t re-iterate this enough, it’s FREE. You get all the benefits of the Free Plan, but with application idling disabled, support for private SSL certificates, and team management with the OPTION to pay to use extra gears and storage.

If this isn’t absolutely clear on our pricing or plan comparison pages please let me know in the comments! If you live outside of our supported regions for OpenShift Online Bronze/Silver plans, help us help you by filling out the Geo Request Form to let us know you’re interested.

Tip 4: Enable Hot Deployment

If you’re using source control to manage your plugins and themes, you can enable hot deployment to prevent your WordPress site from having downtime when you push your changes. Learn how.

Tip 5: Install the W3 Total Cache Plugin

Using the W3 Total Cache plugin with your WordPress installation will significantly speed up your site. Install it from the WordPress admin panel or download it from wordpress.org and check it in through source control.

Update: I recommend enabling both page and database caching in the W3 Total Cache general settings menu with ‘Opcode: Alternative PHP Cache (APC)’ as the caching method for both.

Tip 6: Use CloudFlare

Have a custom domain name for your WordPress site? Route your custom domain through CloudFlare’s DNS service.

CloudFlare DNS Settings

CloudFlare will automatically detect images and static assets on your site and serve them to your visitors using their global CDN. CloudFlare also offers free SSL for custom domains. If you haven’t heard of CloudFlare, check out their features page.

If you followed tip #5, CloudFlare is provided as a W3 Total Cache extension. Setup instructions can be found here.

If you aren’t planning to use W3 Total Cache, follow this blog post.

Tip 7: Use SendGrid for Email Notifications

We recommend replacing the built-in WordPress mail system with SendGrid for improved deliverability and enhanced reporting. There’s even a note about this in our latest version of the WordPress QuickStart in the wp-config file.

Check out the Developer Portal article to learn how to install SendGrid for WordPress on OpenShift.

Tip 8: Add the WP Optimize Plugin

WordPress can generate a lot of waste in your database. Clean it up with WP Optimize. Install it from the WordPress admin panel or download it from wordpress.org and check it in through source control.

Tip 9: Enable ‘Development’ Mode During Development

The latest version of our WordPress QuickStart offers support for advanced debugging. Learn how to enable ‘development’ mode.

Tip 10: Throw Some Money at It

Need to support more traffic? Do you have resource-intensive plugins or themes? Step up to a larger gear size for PHP, your database, or both. We run this blog using the WordPress QuickStart with Large gears – one for the database and another for PHP.

Is your user base largely in Europe? Switch over to any of our Production gears (Small.highcpu, Medium, and Large gears) and re-deploy your site closer to your users in our European hosting region. Learn how.

Tip 11: Backup WordPress with OpenShift Backup Server

If you used tip #2, this step will require you to pay for an extra gear on your account. Still, it’s worth mentioning if you take your application seriously.

Use the OpenShift Backup Server to create one-time or scheduled backups for your WordPress site. It’s the easiest, most complete way to backup your OpenShift applications using OpenShift’s built-in snapshot system for backup/restore.

Tip 12: Risk it with Scaling (experts only)

I wouldn’t recommend scaling the current WordPress QuickStart (beyond separating the database from tip #2 or using larger gears from tip #10). For the more daring and hopefully expert users out there, we plan on releasing an experimental ‘Scalable WordPress’ QuickStart available on the OpenShift Hub shortly. There are quite a few downsides to scaling WordPress without a shared file system, namely that plugins, themes, and updates will have to be managed through source control. Nevertheless, we can try to create a workable solution…together :)


Have your own tips for using WordPress on OpenShift? Share your tips in the comments!

Categories
OpenShift Online, PHP
Tags
, ,
  • Great post! Thanks for all the WordPress tips. Curious what kind of improvements you’ve seen with W3 Total Cache. I disabled it on some some sites at another shared hosting provider and actually saw an improvement.

    • OpenShift

      When we enabled W3 Total Cache on this blog with fairly conservative settings the average “Time spent downloading a page” reported in Google Webmaster Tools was cut in half. I strongly recommend using “Opcode: Alternative PHP Cache (APC)” for both page and database caching.

  • Is Varnish Compatible with WordPress. What About Nginx, memcached solution?

    • Christopher Grello

      Fahad,

      Varnish is indeed compatible with WordPress, though implementing Varnish in OpenShift is a little more complicated than in an IaaS environment.

  • Jennifer Galas

    I prefer WP Super Cache. Can I expect it to work as well as W3 with OpenShift?

    • OpenShift

      WP Super Cache should work fine with OpenShift. W3 Total Cache is a more modern approach to caching that takes advantage of some features OpenShift offers that you wont find in shared hosting environments (like in-memory caching with APC) so I wanted to make sure to point people in that direction.

  • Stefan van Oirschot

    “If this isn’t absolutely clear on our pricing or plan comparison pages please let me know in the comments!”

    A little remark. When comparing the free with the bronze plan, the free plan shows “3 small gears (free)”. This “free” note is not available in the “Bronze plan specs”. So do you pay the 0.02 cents as of the 1st gear or just from the 4th gear and up? If so, the Free tier is nice for some really “Free” testing up-to 3 gears.

    • OpenShift

      All plans include 3 small gears for free. Just curious – where were you looking when comparing the plans?

      • Stefan van Oirschot

        I’ve upgraded to the “Bronze” so i’m not entirely sure about the exact text but….

        My steps:
        Immediately after logging in to OpenShift online I clicked “Upgrade my account” (or something like this) just besides my e-mail address on the top of the screen.
        A new screen with the Free, Bronze and Silver plans compared appears.
        Now knowing I read the “specs” wrong I immediately know where I made the mistake. I read the “Gear sizes” field in the Bronze column and saw a price for the Small gear compared to No price in the Free column. I totally “ignored” the part where it says: “Included(!) gears” as in, for free.

        Thank you for your support.

        • OpenShift

          Got it – yeah that’s definitely not as clear as it could be. Thanks for your feedback! We’re working on an update for that page and a few others in the interface now to make this more clear :)

  • I was looking forward to trying WordPress on OpenShift, moving from a shared host. I have no interest in maintaining a local LAMP server and using git; I just want to manage it online as I always have. But after deploying the quick-start, I’ve discovered that the structure of app-root/data is non-standard for WordPress, with plugins, themes, and uploads at the root level and not under wp-content. So I won’t be able to bulk-restore the current site, and I guess I’ll have lots of changes to make since all photos etc. will have changed paths?

    Is there a guide for migrating existing sites? I’ve seen several references to http://www.cataclysmicmutation.com/2012/06/migrating-wordpress-to-openshift/ but that no longer exists.

    • Completely agree. The strange file structure breaks a lot of plugins, most importantly backup/restore plugins used to move the site between dev and prod. This is a no go. Too bad…

      • Jacob Lucky

        Just use OpenShift’s built-in backup and restore features instead of a plugin. See tip #11.

        • As I said in my comment, backup/restore is also a way to move the WP site from development (my machine) to production (openshift ?). OpenShift’s built-in backup cannot provide that.

          • Jacob Lucky

            Got it – I assume you’ve tried the plugins and they didn’t work? Let me know what plugins you’re using and I’ll see if I can come up with anything.

          • I was hoping for a workflow like this as well. My team and I want to make changes locally in our dev environment and then commit and push them to the gear when they’re ready to go live, just like we do with our application code. Will this ever be possible on OpenShift?

    • Jacob Lucky

      Paths will not need to be changed. The deploy process creates symlinks to map the default WordPress file locations to the new locations in OpenShift’s persistent storage directory. I’ll see if I can put a migration guide together this week, but really the README.md sums things up for the most part: https://github.com/openshift/wordpress-example

  • Jacob Lucky

    You’re storing all of your data in ephemeral storage. Any changes you make in production, such as changes made via the WordPress admin panel (WordPress updates, plugins, .htaccess modifications, images, etc), will be discarded on your next git push. That’s the reason for the awkward file structure we’re currently using. All of the themes/plugins are copied over to persistent storage ($OPENSHIFT_DATA_DIR) on deployment. Look for a much friendlier WordPress file structure when OpenShift 3 is released – check out openshift.org for details on OpenShift 3 :)

    • Jacob, thanks for your reply and for the explanation of the file structure. As I mentioned, I don’t have or want a local copy of my site, and I don’t use git or the “deploy” process. So far I haven’t needed the OpenShift command-line tools. All I did was restore my site and set up a cron script to back up the site and database as usual.

      Maybe this approach makes me an odd duck in the OpenShift world, but I have to think that 95% of WordPress sites run solely on the host. Perhaps OpenShift could develop a simple, non-git, “host-only” WordPress option for those of us who simply want to move from a shared host to PaaS.

  • Guillermo Conde

    Great post.

    I have a WordPress app deployed 5 month ago whit php 5.3 and Mysql 5.1. When I try to upgrade as you say in Tip 1 or Tip 2 the system gives me an error. Can you help me?

    I tried> rhc create-app wp-new php-5.4 mysql-5.5 –from-app wp-old
    The error was >
    Do not specify cartridges when creating an app based on another one. All
    cartridges will be copied from the original app.
    Usage: rhc app-create [… ] [… VARIABLE=VALUE]
    [-n namespace]
    Pass ‘–help’ to see the full list of options

    • Jacob Lucky

      Good catch. The post has been updated – follow the instructions in tip #2.

      • Guillermo Conde

        Thanks.
        I’m trying the tip2 another time, but I get several errors.
        In windows I get an “out of memory” and in linux I get a “timeout”.
        … Work in progress …
        :)

      • Guillermo Conde

        The next problem that I found is:
        – Restore a little snapshot in a non scaling app works.
        – Restore a little snapshot in a sclaling app (wordpress or php 5.4+myslq 5.5) doesn’t work. It seems that the problem is in mysql, it doesn’t import the data.

        • Jacob Lucky

          Interesting – are you trying to move from a non-scaled application to a scaled application? I just ran the steps from tip #2 with a scaled application and everything ran fine. I created a PHP 5.3 / MySQL 5.1 scaled app and migrated to a scaled PHP 5.4 / MySQL 5.5 app without any issues:

          PHP 5.3: https://php53a-jlucky.rhcloud.com/
          PHP 5.4: https://php-jlucky.rhcloud.com/

          • It’s not clear if SQL data is exported/imported as part of the snapshot creation and restore. (See the unanswered http://stackoverflow.com/questions/28497589/sql-database-not-restoring-on-openshift.) What happens if you add a new WordPress post before upgrading?

          • Jacob Lucky

            The database is copied over (along with my username and password). If in doubt, you can find the database backup within the {app-name}.tar.gz at: /app-root/data/mysql-5.1.tar.gz

          • Jacob Lucky

            Alright – I see the combinations that don’t work. When migrating from a non-scaled to a scaled application (or vice versa), the database will not be imported during the snapshot restore. I’ll post a workaround for this in a second. The database does get backed up during the snapshot save, so restoring shouldn’t be a big deal.

          • Guillermo Conde

            Yes, that is what I am trying. Move a non-scaled wordpress to an scale app.

  • Alhikmah University

    My website simply DISAPPEARED!!!

    I followed everything to the letter and to my surprise after getting “DONE” report while restoring, my website still displays the default page and NOT the restored site.

    • I think this is due to changing the scale from “Maximum : All available” to enything else while using a QuickStart WordPress installation.

  • Tony Thijs

    Using cloudflare, which IP adress should I register in the A record at my domain registrar? What if I cannot assign a new DNS at the registrars site

  • neotec

    Thanks for the great post! But I have two questions that I couldn’t find an official answer from OpenShift:

    1) For hosting WordPress on OpenShift and use OpenShift’s modified WordPress code structure, how do I set up a local development environment? For example, after I’ve cloned the repository to my local machine, there’s no WordPress core code at all. How should I set up the complete code locally so that I can run WordPress locally? Is there a step-by-step tutorial for that?

    2) If I don’t run WordPress locally, but only modify code locally and push it to OpenShift, how should I upgrade the WordPress core code when there’s a new release? I would see the release notice in my Admin control panel, but I guess I shouldn’t click and update code from there, right (because the changes wouldn’t be committed to the repo)? What is the correct way to do that (especially whenI don’t have a complete wordpress core code in my local repo)?

    Thanks!

    • Jacob Lucky

      I’ll reply back if I come up with anything reasonable for #1 (possibly involving symlinks from a separate WordPress directory and port forwarding for the database). For #2, simply use the admin panel to upgrade WordPress since we’re not storing the WordPress Core files in the git repo.

  • Deepak

    Hi, I just upgraded from free plan to bronze because of gear idling, but my intention is to stay free by limiting myself to 3 gears. It is not clear from the documentation if I will get charged if I use ssl for my custom domain on the bronze plan?

  • This ET post has helped me more than the 2 hours of plugin research I did on other sites yesterday! Not joking at all. I love how the ET blog posts are so well-written. So many other WordPress related sites just want to get your hit on a search engine and don’t seem to care so much about the content quality.

  • Kirtan

    Exactly. This also doesn’t break any plugins and works smoothly. For the users migrating from shared hosting this can be difficult to understand and using git for wordpress — I am still not getting it.

    It is very useful to just simply put wordpress as it is with the php instance. Thanks for the wonderful blog post. Helped me to save my bunch of time with the troubleshooting.

  • Tom

    Thanks for the post. But how can I add the phpMyadmin to this application, I need to change something in the database but I cannot do it here without the phpMyAdmin.

    • Jacob Lucky

      When you move your database to a separate gear phpMyAdmin can no longer be installed.

      Fortunately, OpenShift still makes connecting to your database easy. I use Sequel Pro or MySQL Workbench on my local machine to manage my databases on OpenShift. Install the OpenShift command line tools (RHC) locally, run `rhc setup` to get the tools setup, and then run `rhc port-forward -a ` to setup port forwarding for your application. The port-forward command returns a local IP Address and Port you can use to connect to your database. You can get the name of your database, username, and password from the OpenShift web console.

  • Eugene Pik

    It seems the option #3 (Upgrade to Bronze to Disable Idling) is no more free. Is there per CPU hour billing, or I do not understand the pricing correctly?

  • I have been hosting my first WP site on Open shift. It gave me quite good learning process. Thanks for sharing these tips was useful to me.

  • Chirag

    Thanks for such a nice post.
    I have a small doubt regarding #6 after adding the two cname
    what about the attribute “A” do we need to remove the attribute “A” in DNs settings as it expect the IP address only and in case of openshift we don’t have any static IP address.

    Also in openshift application what should be used as Alias one with www or without www