Testing MySQL Connectivity From WordPress Docker Containers

cargo container lot

Moving forward with feature development for the Store Locator Plus® SaaS service includes moving forward with our tool kits and environments. Docker containers have become a bigger part of our development toolkit. They make for rapid deployment of isolated environments for testing various concepts without the overhead of virtual machines. While we have been working on Virtualbox virtualized machines for years, Docker is far faster to spin up and far less resource intensive.

Along the way we have found the need to perform deeper dives into the interplay of Docker, WordPress, and MySQL. The latest endeavor, discovering why our WordPress container is not communicating with our AWS hosted Aurora MySQL test data set.

While we can connect to our Aurora MySQL database using the credentials is our docker-compose YAML file, the WordPress instance running in docker on localhost is throwing connectivity errors.

Assumptions

For this article we assume a rudimentary knowledge of Docker, a baseline container with WordPress installed — likely from the default WordPress image, and a GUI interface such as Docker Desktop for managing instances and providing quick access to the shell command line of the container.

We also assume you have a docker-compose.yaml config file that is used to startup the container that looks similar to this:

version: '3'

services:

  wp:
    image: wordpress:6.0.1-php7.4-apache
    container_name: wp-slpsaas
    platform: linux/amd64
    ports:
      - '80:80'
    environment:
      WORDPRESS_DB_HOST: 'some_rds_instance.c0glwpjjxt7q.us-east-1.rds.amazonaws.com'
      WORDPRESS_DB_USER: wp_db_user
      WORDPRESS_DB_PASSWORD: '9aDDwTdJenny8675309'
      WORDPRESS_DB_NAME: wp_db_name

And you’ve started the container either via Docker Desktop or the command line with
docker-compose up -d

Installing MySQL Client On Docker WordPress Containers

Connect to the shell for the container after the container has been started. The easiest way to do this is with Docker Desktop and clicking the shell icon for the instance.

Our SLP SaaS container running WordPress in the Docker Desktop. The red arrow is the icon to connect to the container’s shell command line.

By default the WordPress Docker image does not contain very many tools. That is to be expected as the whole idea behind the containers is lightweight environments. As such we’ll need to install the MySQL client with apt:

apt-get update
apt-get install default-mysql-client

Checking Connectivity To The WordPress Database

With the MySQL client installed we can now test connectivity from within the container to our AWS database directly. This ensures our network configuration and docker-compose environment variables are set properly to communicate with the database.

mysql -A -h $WORDPRESS_DB_HOST -u $WORDPRESS_DB_USER --password=$WORDPRESS_DB_PASSWORD $WORDPRESS_DB_NAME

MySQL > show tables;

If you get a list of WordPress tables the connectivity is working.

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

Vue – JavaScript Library Outside Google/Facebook Control

River Siene Paris Aug 2018

Vue is running on several projects to create a better admin user experience. Vuetify is layered on top and baked into WordPress themes and plugins.

You will need to add a little custom CSS to stop WordPress from stomping on the UX. You’ll also add a small localize script to seed Vue with relevant data from WordPress. A little REST applet to serve Vue requests and you get a fast good looking responsive app with far less effort than custom code, WordPress skeleton apps, React, or Angular.

Vue + Vuetify is my new go-to tool for plugins and themes.   I am happier with my choice knowing that was created and is supported by small independent developers.

Read the article: www.wired.com/story/the-solo-javascript-developer-challenging-google-facebook

Why WordPress REST Performance Sucks

WordPress REST performance sucks.   There, I said it.    Not because I dislike WordPress — in fact I think it is the best open source web application we have seen thus far.    It is a great piece of technology.    It even has the potential to be a great web application framework — in fact I use it for the Store Locator Plus managed service, MySLP.

However, unless you are in 100% complete control of every component in the system you are going to very likely end up with an underperforming over-burdened web service if you build your tech on typical WordPress components.    Even the highly customized MySLP service is 5-10x slower than it would be if it was build on a completely customized application stack outside of WordPress.

Why?

WordPress is NOT built around performance.   WordPress is built on two core tenets – ALWAYS support legacy users at all costs.    Be extensible.

Read More

Cypress.IO Data List Processing — Testing A WordPress Plugin

Testing Store Locator Plus with lots of locations is a chore.  Thankfully Cypress.IO data list processing makes this a lot easier.

It turns out that the old-school Selenium IDE scripts that we’ve been using to test Store Locator Plus for years will no longer work.   We already knew Firefox versions beyond 54 broke things — but we kept an old install on hand so while we port 500+ test scripts to a new system.   What finally broke the old-school Firefox bandaid was moving Store Locator Plus towards a reactive application using Vue.

Read More

%d bloggers like this: