Fix for ‘error establishing a database connection’ after homebrew update

I build WordPress websites in a local development environment powered by Laravel Valet. I’ve been using this setup for a couple years now. It’s fast, light weight, and it’s been awesome – until it isn’t. 😉

This has happened to me twice in the last 6 months.

I run an alias for a few homebrew update commands…

brew update; brew upgrade; brew cleanup; brew doctor;

At the end of the summary of what’s been updated, sometimes a little advisory pops up and advises me to run brew prune to remove unneeded files.

brew prune

All of the sudden, my local development sites start failing to find their associated local database.

The first time it happened, I couldn’t find a good solution and ended up losing some data and starting over–completely rebuilding my development environment.

When it happened again yesterday…

I hunted for a solution for a little longer. I did not want go through that again.

Turns out there’s a really simple fix.

Apparently, when brew prune gets run, a temp directory gets removed. I figured I’d write this down to save myself a headache next time this happens.

Recreating that directory and restarting MariaDB or MySQL will restore access to your local databases.

mkdir /usr/local/etc/my.cnf.d
brew services restart mariadb



Setting custom field values on old WordPress posts in bulk via WP-CLI

If you are a WordPress user that takes advantage of custom fields and WP-CLI… this may interest you.

Let’s say you’re using ACF field groups on posts in a certain category. You have a new custom field with a default value you’ve added to that field group. You’ve already modified the template to conditionally show a piece of UI based on that field value. Finally, you realize that now you’re going to have to open each post in the editor, one at a time, to save it in order to get that field value set.

Or… maybe there’s a way to script it?

In my situation, I only have about ten posts that need this treatment, but if I was looking at manually updating each post to include that new default value across hundreds of posts… /shudder

I decided to research & teach myself the steps I’d need to work through if I ever find myself in that situation.

Where are ACF values set in the database?

ACF field values are stored in the wp_postmeta table.

custom fields in wp_postmeta

There are actually two rows in post_meta. One is the actual value. The other is a reference.

Test: Update one post via WP-CLI

We’re going to try using wp post update1.

wp post update 4045 --kjzz_has_audio=1 --_kjzz_has_audio=field_59038b5c9457b

Successfully updating meta on a specified post

Ok, that’s a good start.

How can we affect only posts in X category?

Thankfully, in my situation, all the posts I need to affect belong to a specific category. I can grab a list of the post IDs with this:

wp post list --category_name=category-slug --format=ids

The whole command

So, now I need to combine the two.

Like most situations in life, I can’t be the first person to be in this boat. Someone has to have written about this in the past, right?

After a little searching, I ran across Updating Multiple Posts’ Meta | Mika Epstein. Check out Mike Little’s suggestion in the comments… That looks promising!

And this is what I ended up with:

for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post update $id --kjzz_has_audio=1 --_kjzz_has_audio=field_59038b5c9457b; done


Successfully updating meta on a specified post

Victory Almost.

After inspecting a few of the records in Sequel Pro, it looked like the ones that already had those custom fields were ‘updated’ (to the same value), but the ones that didn’t have those custom fields yet did not actually get new meta added.

Looks like we’re actually going to need wp post meta and we’ll need to update/add each meta key/value individually.


for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post meta update $id kjzz_has_audio 1; done


for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post meta update $id _kjzz_has_audio field_59038b5c9457b; done


… Now I’m wondering if I could have used:

for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post meta update $id kjzz_has_audio 1 && wp post meta update $id _kjzz_has_audio field_59038b5c9457b; done

  1. Nope. Close… but that doesn’t add the custom fields if they’re not there ↩︎

Offline Docs

You know those moments of realization where you discover something and feel like you’ve had your head in the sand for years?

That’s been my morning.

I just discovered Dash (or Zeal for Linux/Windows users) and I’m loving it!

Dash is an API Documentation Browser and Code Snippet Manager. Dash stores snippets of code and instantly searches offline documentation sets for 150+ APIs (for a full list, see below). You can even generate your own docsets or request docsets to be included.

If you dabble in web development at all, Dash is worth a download. Here are the docsets I grabbed without effort – all available for quick search.



Operation Homecooked Mobile Device Lab

TL;DRI’m a web developer nerd that wanted to test my sites on multiple devices at once. So, I built a thing to do that.


I’m the in-house web developer at an excellent CPA firm in Southern Arizona. I build/maintain all their web properties – internal and external. As it stands, all but our main site are responsive and feel modern-enough1. Our main site is based on a non-responsive WordPress theme I chose (D’oh!) in 2010 that’s been heavily customized over the years2. It needs a major responsive redesign – yesterday! Based on other job responsibilities/projects, I haven’t had time to focus on it until now. As I really started to stare the project down, I started to wonder how I’d make sure the new theme looked right across multiple devices.


The proper way to go about this would be to identify ‘target devices’ currently used by our visitors via our analytics provider of choice. However, at least initially, I’m attempting to do this on my own dime aka «on the cheap» … so, I’m using whatever I can get my hands on. I currently have access to:

  • iPad w/ Retina screen (Previously provided by employer)
  • iPhone 5s (Previously provided by employer)
  • Kindle Fire
  • Droid X

Use what you can! Perhaps you own an Android phone… Tell your friends what you’re doing and ask if you can borrow a previous-model iPhone that they’re not using or something. I’m hoping to get my hands on a newer Android device or two – especially if they’re different screen sizes. I’m debating whether or not to send an email to the firm asking folks to donate a dusty device or two.

Available Solutions

Thankfully, in this day and age, we’re able to hop on the internet and look up how other folks have solved similar problems. After poking around the web, I found a cool project/movement called Open Device Lab. It aims to highlight device labs that are open to public use for free and encourage the creation of more. It’s certainly a very cool idea; one that I think could be a really cool addition to any of the co-working locations in downtown Tucson. However, it’s an idea I don’t think I can pitch w/o having a working example to demo.

The well-made, professional solution

I’m just gonna leave this here and say, yeah… looks really nice.

Vanamco’s $149.00 Device Lab

My improvised solution

Stand hardware

Items from Home Depot & Amazon:

Note: If you anticipate needing to test more than 4-5 devices, you may want to double up on these items. The beauty of the pegboard used in this build is that it’s designed as an expandable system. Two of them will lock together really nicely with a couple screws.


There are two pieces of software magic that make this setup work beautifully.

DesktopServer by ServerPress

Cloudup rjmauqxttnm

You can certainly pull off this setup with any local web server stack (MAMP, LAMP, XAMPP, VVV) or with ServerPress’ free version, DesktopServer Limited, however, I want to point out that after using that version for a few hours one day a couple months ago, it was enough to convince me to upgrade to their fully-featured DesktopServer Premium version. I have not been disappointed.

DesktopServer allows you to quickly and easily generate optimized WordPress projects that run locally.

Prior to DesktopServer you would have had to install a LAMP stack, edit multiple configuration files, create databases, create security credentials, and repeat the process for each new project or site you wanted to run; a painful time consuming and unfriendly process for non-developers and seasoned programmers alike. DesktopServer diminishes mundane tasks and is preferred even by advanced developers who like to tinker with WordPress Multisite based projects, domain aliases, and host files.

ServerPress has done a great job putting together a software package for Mac or Windows that lets you run a local version of your sites quickly, with very little fuss.

ServerPress’ Videos

For more information on how DesktopServer can exceed your needs, hit their YouTube channel!


If DesktopServer is the cake, BrowserSync is the frosting. It allows you to inject live-updating code into your pages and then sync scrolling, mouse clicks, and form input across any browsers viewing the URL on the same network. No more saving your code, switching to each browser you’re testing in, and refreshing the page. It refreshes each connected browser automatically. It’s free, open source, and ridiculously wonderful.

I’ve got it hooked into my Gulp build process. PHP, JS, and SCSS files are watched, compiled/concated on-save, and all connected browsers are refreshed w/ the latest changes.

Here’s the gulpfile from one of my projects:

Solving Real Problems

Using the hardware and software covered above, I was able to tackle a pain-in-the-butt issue last week. Long story short: we had embedded a survey (thanks Survey Monkey) into a dedicated, responsive landing page on our site. In testing, the survey loaded when viewed on an iPad or any computer… but it wouldn’t show up on any phones we tried. Using the device lab, I was able to discover that Survey Monkey’s embed javascript was specifically NOT rendering the form on any devices with a screen smaller than 760px wide. From that Ah-ha moment, I was able to build a ‘warning’ pane that would only show up on the smaller screens offering to launch the survey in a new view.

Mobile Device Lab getting it done!

BOOM! Problem solved!

Future Plans

Obviously, the goofy Guitar Hero stand needs to be replaced by a sturdy solution of some sort. It does the job for now, but I’ve already spent some time sketching out some ideas for a wooden frame (with room for two panels mounted together – I went ahead and bought another one :)).

For now, version 1 works really well for me.

Operation Homecooked Mobile Device Lab is a success!

I’ll definitely add photos of version 2 when it gets to that point. Perhaps that’ll be one I can replicate down at CoLab Workspace or Connect Co-working?

1: Everything changes so fast on the web, I don’t dare declare anything modern or ‘done’. ^

2: A year or two after launch, we added a mobile device sniffer and have been redirecting that traffic to a /mobile/ subdir… which has worked well-enough. But it’s 2015, dangit! Time for a completely mobile-friendly approach. ^


To the WPmobile!

WordPress sticker on my windshield

Around this time last Saturday, I was driving up to Phoenix for Press Publish. Felt like I earned extra points for showing up w/ a big WP sticker on my car.


Wapuunk Grey T-Shirt – Hello Merch

Not gonna lie… tempted.

Wapuunk Grey T-Shirt at

Wapuunk Grey T-Shirt – Hello Merch

Update: I changed my mind. I want this one.

Samurai Wapuu Black T-Shirt


Talk: Quick WordPress Protection

I had the opportunity to speak at tonight’s Tucson WordPress Meetup which had a focus on security.

It was a short intro to Jetpack Protect (formerly BruteProtect) and a small .htaccess mod to restrict access of wp-login.php to specific IP addresses. It went well.

Hopefully, I got some folks to at least change their admin account and use unique passwords.


Proof you need math after high school

See kids?

Better keep studyin’.


WordCamping in San Francisco from Tucson

WordCamp San Francisco 2013 was the first WordCamp I’d ever attended. I was lucky enough to go w/ my wife and we both had a great time. We were really disappointed when we realized we wouldn’t be able to make it back for WordCamp San Francisco 2014. (Fingers crossed for 2015!)

Thankfully, they’re offering livestream tickets!


I scooped up a livestream + t-shirt ticket and threw the date on the calendar. But as the hours ticked by after that purchase, I started to think it’d be nice to invite other local WordPress users over and share the experience. My wife took it a step further and suggested we use one of the locations the Tucson WordPress Meetup group has used recently.

About the same day, this post went up re: viewing parties.


The Tucson WordPress Meetup is hosting a Viewing Party

If you live in Tucson and use are the slightest bit curious about WordPress and/or it’s community of users, RSVP and join us this coming weekend (October 25 & 26) for a great look at both. There are two full days of great speakers scheduled. We’ll have two different rooms setup to view both tracks. Lunch is provided on Sunday by Nuanced Media.

Oct 25-26, 9am-6pm, CoLab Workspace

If you find yourself too far from SF or a local WP Meetup group, they’re still selling livestream tickets here. You can watch in the comfort of your home!

Twitter List of WCSF Speakers

Compiled by David Bisset – Subscribe to the list or follow the ones that knock your socks off.


GuestAdditions and Subtraction

Like many WordPress developers lately my day starts and ends with Varying Vagrant Vagrants. VVV’s really worth a look if you’re still working with MAMP, WAMP, XXAMP, or something similar. Truth.

Sidenote: vvv-site-wizard

Alison Barrett‘s vvv-site-wizard tool is the hotness. And despite what was preached at our local WP meetup… It does work on Windows.

Problem 1: guest additions do not match!

VVV relies on VirtualBox and Vagrant. I encountered some trouble w/ a sub-part of the puzzle this afternoon and I figured I’d share my adventure. Over the last couple days, I’d been noticing this fly by in the console during my morning vagrant up

do not match

Me: “Crap. Maybe I should think about updating that… I guess.”

Thankfully, there’s a plugin for that – vagrant-vbguest!

Solution 1: update guestadditions w/ vagrant-vbguest plugin

Whee! Success!

GuestAdditions 4.3.10 running --- OK.



Problem 2: now folders don’t mount

My VirtualBox GuestAdditions were successfully updated to 4.3.10. Unfortunately, there’s a known bug in that version that prevents mounting shared folders (Note: this will be fixed in 4.3.11). Subtraction. It’s what I literally uttered as an expletive this afternoon. Had I run across the vagrant-vbguest Issue before installing, I would have waited.

At this point, now my vvv environment wouldn’t fully load w/ a vagrant up.

Solution 2: a new symlink!

Thankfully, the fix for this subtraction was found in that GitHub issue I linked above. Felix Rabeprovided (and cited) a solution that worked perfectly for me.

vagrant ssh

In my case, it was opening a PuTTY session to the vagrant box.

sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

Then, outside the VM:

vagrant reload

For me, it reloaded successfully, but my dev sites weren’t functioning (MySQL failures) until I ran:

vagrant provision

I was back up and running!


Discovered a problem that wasn’t really affecting me. Decided to fix it; caused major breakage – halting my work day.