For years I’ve learned by jumping in with both feet often without looking. While sometimes beneficial, other times it can be….problematic. I tend to find a tool or service that I like and stick with it….until I find something better. Often these things work great “out of the box” and have minimal headache. Other times I’ve been forced to spend hours (or days) meticulously and painstakingly troubleshooting and bending it to my will.
A prime example of this is when I moved from a general tech support role into a hosting support environment. I had used Linux in passing sure, but the company was cheep and Linux was free so each work station was set up with Kubuntu. It was about as delicate an introduction as I could get to using Linux regularly. That’s not all that was new, with hosting comes servers! Thankfully cPanel was the most common and fairly straightforward (We don’t talk about Plesk).
But what are you going to do with that hosting server? You want a website right? Obviously. So there are lots of options to choose from. You’ve got your website builders (Weebly, Wix, SquareSpace, etc) for easy drag and drop template building. There’s the age old classic of coding with HTML and PHP or using an IDE (cue Dreamweaver flashbacks). There are also plenty of CMS (Content Management System) options to choose from. Among these were usually WordPress, Joomla, Drupal, Magento, and some Concrete5 thrown in.
Going from supporting printers and school websites for college kids, eCommerce was a big jump. These people aren’t chill and relaxed like students. If they have a problem, they are loosing money and it’s your fault! Not their theirs, the developers, hackers, or even the companies fault. Yours specifically, and they will be sure to let you know. So where time = their money and my sanity, I realized I had to learn how to fix things fast. I looked at the most common issues that were brought up and determined to know how to fix it as fast as possible.
WordPress was by far the most popular platform. They claimed to make up 42% of all websites and often an entire day would go by with all of my interactions being WordPress sites. I learned slapdash ways of getting things done quickly. Facing a WSOD (White Screen of Death)? I’ll go into your files and rename the plugin folder to deactivate them to see if that fixes it. What? Renaming the folder back after the issue was something else didn’t bring the plugins back online? I’ll just turn all the installed ones on at once, I’m sure it will be fine…
Learning how to do things fast wasn’t good enough. I had to be safe as well. I had to understand how it was all related. I had a coworker who had been there a few years. Not only did he introduce me to command line/terminal, text expansion programs, and bash scripting but a fusion between all of them: WP-CLI. This was yet another huge learning curve. Oh you know how to do in depth complicated things on a computer? Now stop using everything but text. Might as well unplug the mouse, close your web browser, and type on an empty black screen. It’s the same thing.
In the interest of learning all these things at the same time (because how else would you do it?), I started making shortcuts through text expansion programs. If I could learn how to do something in terminal just once, I could make it into an autokey and never have to know how to do it the long way again! Making a quick backup? Just type 'ctar
(for create tar, get it? I thought it was cleaver) and watch it turn into tar -cvf
so you don’t have to remember the flags/variables each time. Extracting your backup? 'xtar
gets you tar -xvf
to extract it. This went on for some time until things got more complicated.
Whats better than shortcuts? Not having to type them all the time! I started by learning about functions and basic bash scripting:
function name() {
commands
}
Make the function, pop it into a file then just run bash file.sh
and it does what you programmed it to do. It doesn’t matter how much is in the function, it follows your instructions line by line. So what do you do? Make a bunch of files and have to upload them to each website you work on? That seems like going backwards. Eventually I learned that Linux has a lovely command called curl
. That handy command lets you “transfer data from or to a server using URLs”. I could put my code online, and pull it to whatever server I was working on as needed. I didn’t need to clean up after myself as there were no files to remove.
I’d hit on an idea and was learning bash and WP-CLI commands as fast as I could. I was getting much better but it was still a lot to remember. I kept at it and eventually wrote Quick WP-CLI. It started by collecting information I could use to fix problems:
WPCLI Check: [OK]
Checksums: [OK]
Eval Plugins: [CHECK]
Eval Themes: [CHECK]
WP Version: #.#.#
Site URL: https://example.com
Home URL: https://example.com
Stylesheet:
Template:
Database Conn: Success
Database Name: db_name
Database User: db_user
Database Pass: PASSWORD
Database Host: localhost
Database Prfx: wp_
PHP Version: #.#.# Max Input Vars:
Core Updates: # Memory Limit:
Plugin Updates: # of # Post Max Size:
Theme Updates: # of # Upload Max Size:
Having the power to pull all that information by typing wpstats
was amazing. I had the information I needed to fix just about any issue before the client had finished explaining it.
Naturally the next step was fixing problems with the same ease:
### REPLACE CORE WITH SAME VERSION ###
function wpReplaceCore(){
version=$(grep 'wp_version ' wp-includes/version.php | cut -d\' -f 2)
echo -e "Replacing existing core with fresh $version files"
if [[ ! -e "wordpress-$version.tar.gz" ]]; then
if ! wget -q "https://wordpress.org/wordpress-$version.tar.gz"; then
echo -e "Unable to download wordpress-$version.tar.gz"
return 9
else echo "Downloaded wordpress-$version.tar.gz..."
fi
else echo "wordpress-$version.tar.gz already exists! Please rename!"
return 1
fi
temp=$(date -u +"%Y_%m_%d-%H_%M")
echo "Checking for existing WordPress files..."
local wpfiles=$(find -maxdepth 1 -name "wp-*" -o -name index.php -o -name license.txt -o -name readme.html -o -name xmlrpc.php)
if [[ -z "$wpfiles" ]]; then
echo -e "No existing WordPress files found..."
else
oldWP="QWPCLI_CORE_$temp"
echo -e "Old WordPress files found! Moving them to$COL_WHITE $oldWP..."
mkdir "$oldWP"
while read -r f; do mv "$f" "$oldWP"; done <<< "$wpfiles"
fi
tar -xf "wordpress-$version.tar.gz" --strip-components=1 && echo "Unpacking the update..."
rm -f "wordpress-$version.tar.gz" ### && echo "Removed wordpress-$version.tar.gz..."
if [[ -d "$oldWP/wp-content" ]]; then
mv wp-content wp-content_"$temp" ### && echo "Moved default wp-content to wp-content_$temp..." &&
mv "$oldWP/wp-content" . ### && echo "Moved old wp-content back into place..." &&
rm -rf wp-content_"$temp" ### && echo "Removed wp-content_$temp..."
fi
if [[ -f "$oldWP/wp-config.php" ]]; then
cp "$oldWP/wp-config.php" .
### echo -e "Copied old wp-config.php back into place..."
echo -e "Success: Core replaced with stock $version files"
else
cp wp-config-sample.php wp-config.php
echo -e "Warning: No previous wp-config.php found! Used wp-config-sample.php..."
fi
echo -e "\nCompressing old WordPress core..." && tar -zcf "$oldWP".tar.gz "$oldWP" --remove-files && echo -e "Success: Old WordPress files located $oldWP.tar.gz"
wp --skip-plugins --skip-themes core update-db --quiet
}
This again, changed everything. By the time someone had finished explaining what was wrong, the issue was fixed, and I’d updated a handful of settings to make things run more smoothly. I was left to chat with client a bit, have them refresh the page and thank me for having it fixed so “easily”.
So with all the power of my creativity behind me, things got much easier at work. My handle time for issues got cut in half and I actually got in trouble for that, until I had management check my customer survey ratings as well. Needless to say that “problem” went away fast.
As the years have gone by I’ve explored countless possible projects and made my fair share of them. This blog will be my own personal wiki of sorts for my projects. I’ve often found very niche pieces of information on the internet after scouring it for hours. Sometimes I need that information again years later and even if I remember the site, there is no guarantee it is still there. Projects get shut down, things get removed from the internet and lost to time. So I’ve become an Archivist and try and save the bits important to me. But more on that next time.