Other posts in this series

A Series of Three Parts: WordPress as a SaaS Platform, The Second Part

So, you’ve decided to use WordPress as your application platform. Where do you start so your application performs well and scales easily? Well, setting up an efficient WordPress application is one part web server configuration and two parts clever application software programming. Start with a good server architecture, well programmed plugins and themes, the right WordPress installation mode and you’ll set yourself up for success.

Server Configuration

A good server setup is key to having a well-performing WordPress application. Shared hosting solutions you may normally use for a WordPress blog are not going to cut it for a full-blown application that thousands (and eventually hopefully millions) of users will be logging in and out of and interacting with on a regular basis. Your best bet is your own custom software stack, or a server, as a solution partner if you’re less command-line inclined (more on that later).

LNMP, is the new hotness. LAMP is old and busted.

For Hello Bar we set up a higher performance web server stack using an LNMP stack (Linux, nginx, MySQL and PHP-FPM). The combination of nginx and PHP-FPM (PHP as a FastCGI Processed Module) with APC installed make for a much faster, lighter weight, lower memory use server stack that can help you scale your application easily and not force you to scale as early. Iliya Polihronov recently gave a talk at WordCamp San Francisco about setting up a WordPress server using this stack and provided a great starter configuration for your own stack. EndofWeb also has a great article on setting up a full server stack from scratch using Ubuntu.

Cache ALL the Things!

When dealing with thousands of requests per second, caching is the best thing you can do to speed up your web application. With Hello Bar we utilized everything including APC for Object caching and for speeding up PHP in general, Batcache with Memcached to cache publicly viewed pages, and even file caching with nginx and URL rewrite capabilities. Caching systems that allow your web server to pull the cached data directly, avoiding PHP all together, provides a huge performance boost to those portions of your application. There are many caching technologies available and numerous caching plugins to help cache your web application. Just make sure that you are writing your application to clear caches when they need to be. You don’t want a list of entries a user has made to not update because the cache is stale.

Cache All the Things!

All the Things! from Hyperbole and a Half

Replicated Database

When running a high traffic site, one of the biggest bottlenecks becomes the database. Luckily, WordPress’ database library is implemented in a manner so that it can easily be adapted to a multiple database solution. By using the HyperDB database plugin, you can configure WordPress to distribute individual tables into multiple databases, provide failover support (when a connection to the database couldn’t be made), and most importantly, provide support for replicated MySQL database clusters. MySQL can be configured to automatically replicate any command sent to it to another MySQL database on another server. This creates two or more nearly real-time synced databases that WordPress can read from and serve back data. How To Forge has a good article about setting up a replicated MySQL server cluster and this article by HBY Consultancy also provides some good insight on getting this setup.

Ensuring Good Communication

Communication with your users is important and it’s most likely that you’ll be using email as your primary means of communication. To ensure the greatest deliverability of your email communications and to avoid a lot of the problems that go along with keeping your web server’s IP address white-listed, I recommend that you use an external email service. SendGrid is an easy to setup SMTP server that you can get integrated on the cheap. Just use a simple SMTP plugin such as WP Mail SMTP or WP SendGrid for your WordPress installation and all your wp_mail() function emails will be sent through the reliable, white-listed and stats rich SendGrid service instead of your own host’s email.

Setting up WordPress for Success

While a good hardware configuration makes for a solid foundation for your application, it won’t mean a thing with poorly configured software.

Intelligent and Picky Shopper

Intelligent and Picky Shopper from Shutterstock

Good Plugin Authoring

If you aren’t picky with the community plugins you choose to run or you’re a little sloppy with your own plugin authoring, then your WordPress application can become a bloated beast rapidly. Now, this doesn’t make WordPress a bad platform, it does however require some strategic planning when preparing it for use as an application platform due to its diverse community and ease of entry for plugin authorship. When authoring your own plugins and evaluating community plugins for use, consider some of the following practices:

Sometimes of course there will be plugins that you’ll absolutely want to use in your application, but you don’t need them to load everywhere. Check out something like the Disable Plugins MU plugin for a lightweight solution for filtering out plugins from being loaded where you don’t need them.

Pick the Right WordPress Operating Mode

Depending on the needs of your application, you may want to consider operating WordPress differently. WordPress out of the box is configured to run as a single website installation and this works fine for most situations. If your application is offering lots of user controlled, maintained, and published content, you may want to consider running WordPress Network. This will provide additional super-administrative controls to you as the application owner and provide a better setup for horizontal hardware scaling and opportunities for sharding your databases with the previously mentioned HyperDB or ShardDB.

Lever of Switching

Lever of Switching photo from Shutterstock

A lesser known mode for WordPress to operate in is a headless mode that gives you greater control on exactly what is being loaded and used to process your data. To enable this, just add define(‘SHORTINIT’, true); in your wp-config.php file before the require_once(ABSPATH . ‘wp-settings.php’); line. This will load the bare minimum of the WordPress system and give you better control of customizing what gets loaded. Check out this article on How WordPress Boots Up to get greater insight on what this constant does to your WordPress installation’s normal operating process to see if its the right move for your application.

In Conclusion

Creating a high performance, WordPress-powered application is founded in careful planning and judicious selection of plugins from the community. So with the next WordPress app you build, roll up your sleeves and do some planning beforehand. Make sure the plugins you choose are of good quality, plan your plugin creation strategy for speed and modularity, and lay out your server setup for easy scaling and you’ll set yourself up for success.

Any good suggestions or techniques for setting up WordPress for speed and scalability that I didn’t cover? Contribute to the knowledge pool in the comment thread below!

Useful Links for Building WordPress Applications:
Comments
  • These two articles have been sort of mind blowing. I would never have considered WordPress as a reliable SaaS platform, but you’ve made a great case. Most of your suggestions could also be applied to any popular WordPress blog for some huge improvements.

  • … and another amazing article, you give me another view for “How to scale your server” as it was very hard to me to understand why my website hangs… I’ll try LNMP and feedback about the results

  • u nailed it dude. my whole concept is changed specially choosing wordpress for large scale development.many many thanks 🙂

    • dtelepathy

      You’re welcome! =) We definitely discovered a lot of possibilities throughout the process.

  • Jon Tucker

    Amazing post series. In short, we manage website chat for customers and used this blog series as a guide to use wordpress as a platform to allow each customer to see chats we’ve done for their website.

    We have an issue though. I’m hoping you experienced something similar and can help ; )

    We defined ‘chats’ as a custom post type, and are using S2 member “custom capabilities” to make sure customers only see chats for their website in their account.

    It’s functioning as planned, but S2 member KILLS OUR SPEED – with all plugins deactivated, page load is 0.3s. Totally fine. Once S2 member is activated, it goes from ~ 5s. We have tried a lot, including resizing our server to a storm dedicated server from liquid web with 3.9GB / plenty of spec power and haven’t been able to overcome this challenge.

    Did you guys experience anything similar? If you had a “oh! s2 doesn’t like custom post types at scale – here’s what to look into” you would make my 2016 so far = )

    • jamie3d

      Are you handling cron tasks using the default setup? Or have you moved them to a dedicated server cron job yet? Something like s2member needs to check the users table pretty often (not ideal) for EOT times I believe. It’s just a hunch, but this could be contributing to the slowness you’re seeing. (it’s a total shot in the dark)

      Basically, disable cron temporarily and see if that makes a difference.

  • Rub Fox

    “EndofWeb also has a great article” link not working