Quick fix for sysadmins to manage multiple Wordpress installs (Without WP Multisite)

Most of you other neckbeards out there have had to walk into an IT department riddled with technical debt. The proper thing to do would involve spending time you don’t have redoing whatever is fucked up…. but what if you don’t have time? Well, in this case I hacked together a bash script to work in tandem with wp-cli and went about my day.

So the filthy bastard before me installed 100 individual Wordpress sites on the same server without using WP Multisite. They are all totally fucked up with deprecated plugins, core versions 42 point releases out of date, memcache plugins that connect to a non-existent memcached service.

Well, I’d like to rm -Rf /var/www but the bossman would be sore at me. Instead I strolled over to http://wp-cli.org/ and installed it on the ancient baremetal server housing Satan’s nightmares.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

You can check to see if it’s working as intended by just typing wp in the terminal. The output should be a list of available options.

Hopefully, all of these installs have a common naming convention such as /var/www/html/site1.com/public_html, /var/www/html/site2.com/public_html. If not, feel free to comment and on this post and I’ll see if I can help. However, in my real world scenario this is how the sites were structured on the server.

Now for the script: (Save it as wordpress-update.sh in whatever directory you see fit)

#!/bin/bash
# Remove results.log to make a fresh copy
rm -f results.log
# Create a list of sites to update
ls /var/www/html > sites.txt
# Select the generated list of sites and tell it to read one line at a time
filename=”sites.txt”
while read -r line
# Do the thangs and stuff
do
name=$line
echo “UPDATING — $name”
echo -e ‘BEGIN\n’ >>results.log
echo -e “$name\n” >>results.log
wp plugin update — all — allow-root — path=”/var/www/html/$name/public_html” >>results.log
wp core update — allow-root — path=”/var/www/html/$name/public_html” >>results.log
echo -e ‘\nEND\n’ >>results.log
done <”$filename”
exit 0

This particular script will create a list of sites, run wp plugin update && wp core update on all the sites in the list and then output the results in results.log.

You can perform additional tasks by running the commands found in the wp-cli documentation or just type wp on the command line for full list of choices.

Godspeed on future technical duck tape.