Converting A Standalone Instance Into An EC2 Load Balanced Cluster

Creating a new web application that resides on an AWS load balanced cluster is easy with the Elastic Beanstalk assistant. That is a great solution if you want to run every web service or application on their own instances. It is not a great fit for complex environments like the one being used for Store Locator Plus®.

Store Locator Plus® has several environments running within the same master domain. Multiple servers and load balancers creates a security certificate nightmare. Not too mention it starts racking up EC2 server fees quickly if they each became their own cluster. The better option is to retain a server instance that allows us to run our SaaS offering, our buy-and-own plugin store, our documentation site, and our demo site from a single disk image. We want to setup a full EC2 Load Balanced Cluster to gain the benefits of horizontal scaling on a server hosting multiple domains and web apps.

While this is easy to do with a single EC2 instance that hosts multiple host names for the storelocatorplus.com domain, making it scalable under load is the trick. It turns out Elastic Beanstalk is not a good fit. Instead we need to build a load balanced cluster “from scratch”. We’ll need to combine a machine image from a running server with a Launch Template. We will need an Application Load Balancer that will have instances attached and detached automatically from an Auto Scaling Group that we will also create.

Our environment also has a configured EC2 instance to run the web application stacks, mostly WordPress, locally on an EBS volume that uses an Amazon Aurora MySQL RDS database in multiple zones for performance and reliability. These two features make it easy to replicate the disk image for the software portion and maintain a persistent DB store across all instances.

Read More

WP_User_Query Inverse (NOT) Search

It took a LOT longer than it should have to build an efficient query for WordPress users today. The query — an WP_User_Query INVERSE search.

The list I was trying to generate was based on two things:
– All users with a meta_key field ‘account_status’ containing the status ‘active’
– EXCLUDE all users with a nicename ending with “at_slp_dot_guru”

Turns out this is a LOT more difficult than it should be due to shortcomings in the WP_User_Query class. The solution that created the least amount of data queries , and thus improved performance over other “post filter” methods was to make use of the pre_user_query action hook that is part of WP_User_Query.

The Patch

The short version of the patch — use the pre_user_query to change an “INCLUDE all users with this search value” to an EXCLUDE for those same users. This is done by using the INCLUDE search filter than “flipping the logic” by replacing the field comparison in the WordPress-generated query to NOT LIKE instead of LIKE.

/**
 * Filter out SLP dot Guru accounts.
 *
 * @param WP_User_Query $wpUserQuery
 */
public function filterOutSLPDotGuru( $wpUserQuery ) {
   $new_query_where = str_replace( "(user_nicename LIKE '" , "(user_nicename NOT LIKE '" , $wpUserQuery->query_where);
   $wpUserQuery->query_where = $new_query_where;
}
Read More

Cloning A VVV 2.6 Install

Decided to upgrade my long-term VVV setup that I use for daily client consulting work in preparation for a new gig as head of R&D and CTO for a super cool tech startup. As usual I should have left things alone as it was working fine; I only wanted to play with the newer VVV toys. You’d think I’d learn by now.

What I ended up doing was cloning a working baseline VVV install I had created a few weeks ago for the WordPress Plugin Development class I’ve been teaching at The Blockyard this year as part of the CodeBlock initiative.

Turns out this will be super useful for those nights when we have a dozen students all trying to initialize a new VVV install and we don’t have the bandwidth for 12 simultaneous 500MB box image downloads.

Here are the notes for a MacOS install. Windows will be slightly different but the same concepts apply.

Read More

Ubuntu Trusty: PHP 7.2 MIA

Working with Varying Vagrant Vagrants today and having problems spinning up a new box? Don’t blame yourself. It appears that the PHP 7.2 libs… in fact ALL of the PHP libs for Ubuntu Trusty have gone away.

The ppa:ondrej/php repository that is cited everywhere has decided it is not going to serve up any PHP code to your Vagrant boxes today.

Maybe they’ll fix it soon. Maybe not. If anyone has a workaround please comment here.

Read More

nginx Installing WordPress In A Subdirectory

We have recently run into a number of customers using Store Locator Plus® that are having issues with the new REST based geocoding system. It turns out that an overwhelming percentage of people that are having issues have WordPress installed in a subdirectory. Apparently not all subdirectory installs are created equal — if it is not done properly things break.

What is a subdirectory install?

A subdirectory install is one in which WordPress is installed in a directory within the document root of a website. Sometimes this is done when WordPress is only managing one part of a website such as the newsfeed or blog. Other users use this install to separate WordPress core code from the add-on and upload code (plugins, themes, uploads) and the site configuration.

For the sake of this explanation we’ll reference the document root as being in the public_html directory and WordPress inside of a /wordpress directory within.

Our example install structure
Read More
%d bloggers like this: