Chuck Grimmett

March 2019

Index

  • How to Upgrade from PHP 5.6 to 7.2 for WordPress

    How to Upgrade from PHP 5.6 to 7.2 for WordPress

    Last week I updated three large WordPress sites for Praxis from PHP 5.6 to 7.2. Here is the process I used on all three to make it a smooth transition.

    Note: I do contract work and can help you figure this upgrade out. Reach out if you are interested in getting a quote.

    1. Figure out the scope of the problem.

    First you need to know how much time you should plan to spend doing this work. A quick way to find the scope of the problem is to run the PHP Compatibility Checker plugin. It checks your themes and plugins, spitting out errors, warnings, and filenames/line numbers of the offending code so you know where to start.

    • Small theme upgrades?
    • Plugin updates?
    • Massive refactoring of custom code?

    Even if you get a 100% clean pass with the compatibility checker, I suggest going through the rest of my list. The compatibility checker isn’t perfect. You don’t want to roll those downtime dice. Fool me one time, and all that.

    2. Test the upgrade locally.

    Copy down your current theme and database into your local development environment. This is important. Don’t use the version you have from work you did a few months ago. Stuff changes on the server all the time. Pull down a copy to be safe. Configure your local environment to use PHP 7.2. If you are unsure whether or not you are on 7.2 locally, you can always use a WordPress plugin like Debug Info to check. Also make sure to turn on error reporting in your php.ini.

    Don’t have a local development environment yet? I like Valet.

    While you are at it, I suggest upgrading your WordPress core to the latest version (5.1.1 as of this writing) and updating all of your plugins. Rip that bandaid off. On the plus side, it will probably make the PHP upgrade process easier, too.

    3. Find, diagnose, and solve any issues.

    This is either the easiest or hardest step. If your site looks fine and everything functions as it should, great! You won the lottery.

    It is probably worth double checking that you actually are on PHP 7.2 with the debug plugin mentioned above. Also worth clicking all around your site and checking everything. Sometimes most of the site will load, but you’ll get weird inline error messages like this:

    Warning: Use of undefined constant Y - assumed ‘Y’ (this will throw an Error in a future version of PHP) in /nas/content/staging/creativecourse/wp-content/themes/business-pro-theme/page-archive.php on line 70 

    If you navigate to the site locally and all you see is a sea of errors like I did on one site, you have some work cut out for you. Here are some tips:

    • If the errors include wp-includes or wp-admin in the file paths, you need to update your WordPress core.
    • If the errors include wp-content/themes/ in the file path, and you don’t have any custom work done on the site, the quickest fix is to upgrade your theme or find a new one.
    • If the errors include wp-content/plugins/somepluginname/ in the file path, find that plugin and disable it or update it and try again. You should still be able to get to your /wp-admin/ dashboard even with a broken site because the most recent core works with PHP 7.2.
    • If your site includes a bunch of custom code and the errors are happening with the custom code, you have more work to do. If you are comfortable debugging and fixing it, great! If not, you might need to call the person or company who wrote it. Or decide if you can do without it. Hopefully you followed conventions and put it in a child theme.

    Keep track of the changes you make. I keep a running list in my favorite notes app. Theme updates, core updates, plugin updates, and code changes. Write it all down. Better yet, version control it with git and commit along the way.

    If you have any premium plugins that require activation keys, make sure that you contact the developer to get two extra development keys for local testing and production. Most will provide those to you at no extra cost. Some platforms give you 5 keys per purchase anyway just for this reason. I decided to roll the dice and not get keys for one plugin, and ended up crashing my production site with the upgrade because I didn’t test that plugin. Don’t be like me.

    All three of my sites needed some work done, even the newest of the three. One didn’t load at all until I made some theme updates. One plugin crashed a site and had no updates available, so I had to do without. Some custom code I had written needed updates, too. It took me a few afternoons to sort it all out.

    4. Deploy to a staging environment on PHP 7.2 first.

    Once you have everything sorted out locally and you’ve triple tested everything, go ahead and push your work up to a staging environment. Good hosts like WPengine make having a production and staging environment easy. You can control the PHP versions independently. I use WPengine’s git deployment to move my local updates to the staging server. SFTP works, too. If you need database changes, you’ll also need to do a database migration. Core and plugin updates will need a database migration (Don’t forget to change the site URL or you won’t be able to log in!) If you need to do a database migration, use the instructions here

    My preferred workflow is to copy the full production site (code + database) to staging, push my code changes, then do the core and plugin upgrades on the server (they often involve database changes), which is when my change list above comes in handy. I don’t like doing database migrations unless I absolutely have to, because with lots of users logging in to the site, data is bound to get out of sync with my local version in a matter of hours. Getting back in sync is tricky, so I choose to avoid the problem altogether by only moving code, keeping my change file, and replaying the steps on the staging server.

    If you don’t have a staging environment and can’t get one with your host, or you can’t upgrade the PHP version yourself on your host, then you need a different plan. You’ll need to set up another site on another host that uses PHP 7.2, then put the updated copy of your site there. If you do this,proceed to the alternate #5 below.

    Don’t assume everything works. Test it! Use different user account levels (admin, editor, author, contributor, and subscriber). Try every critical function on your site.

    Only move on to the next step when you are certain everything works like it should.

    5. Deploy to production.

    Before you do anything else here, make a back up of your site and your database. Good hosts like WPengine make this easy. If you are doing this manually, verify the backups work locally. You can to be able to roll back if there is an issue.

    I planned a maintenance window with my users a few days ahead of time. If you have users who rely on the site, you should, too.

    Update your production environment to PHP 7.2, then copy the staging server to the production server. If you are confident that there were no users updating content in between the staging copy above and now, you can copy database and all. If there are changes you don’t want to lose on the production database, you’ll need to use my method and only copy over the theme code, then do core and theme updates on the production site. This is when planned downtime comes in handy.

    Alternate deploy (no staging)

    If you set up a separate site on 7.2 (not a staging environment of a production site) and it works, then you are ready to cut over to the new version. Configure that new site to use your domain (URL field on the setting page), then point your domain’s DNS records at the new server. If you need to do a database migration, use the instructions here.

    6. Verify everything works

    Don’t assume everything works. Test it! Use different user account levels (admin, editor, author, contributor, and subscriber). Try every critical function on your site. Use the Debug Info plugin to verify that the PHP change took.

    If there are any issues, you might need to roll back to an earlier restore point and PHP version (or point your domain back to your other server), or do some real-time debugging. If your production and staging servers mirror each other in every way except PHP version, you shouldn’t run into anything unexpected. If you do, figure out where the difference is and go back to #3 above.

  • Photos Published in Newton Graphic Science Magazine

    Photos Published in Newton Graphic Science Magazine

    Newton Graphic Science Press in Japan published one of my photos twice in the past year. They found it via my Illum project on Flickr and requested permission to publish it.

    Of course, I said yes.

    Here are the spreads the sent me afterward:

    Newton Cycloid 1
    Newton Cycloid 2

    The photo is from a high school physics contest held by the American Association of Physics Teachers where I won Second Place in 2008. Here is my original post from 2008 when I found out.

    Now I’ve been published in Japan. Sweet. Remember to freely share your work. You never know who’ll end up seeing it and what opportunities might come your way.

  • Moving from Homestead to Valet for WordPress Development

    I used to use Homestead for local WordPress and Craft development. It was nice because everything worked out of the box. Well, theoretically. In reality, it worked about 80% of the time, but 20% of the time I’d get cryptic errors from Vagrant like:

    • Some box with the same name exists. We won’t tell you where, but trust us, it exists and that can’t happen.
    • The SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed. The output for this command should be in the log above. Please read the output to determine what went wrong.
    • Error! You have to destroy this box and rebuild it. Hope you backed up those local databases, because they are gone forever!

    It was always a rabbit hole of headaches that could take half a day to resolve. Most resolution happened in the form of me destroying a box and rebuilding it, losing my databases. So much fun.

    Today I got the SSH error again and had enough. I went looking for a better solution and found Valet. Their pitch:

    Valet is a Laravel development environment for Mac minimalists. No Vagrant, no /etc/hosts file. You can even share your sites publicly using local tunnels.

    Sounds great. It won’t eat my battery, RAM, CPU, or take gigs of disk space for vitual machines. Sign up the heck up.

    It was super easy to set up with tools I already use: Homebrew and Composer. Instructions here.

    The only tricky part was making composer directory available in my Mac’s PATH, since I’ve only ever used it inside individual projects. Turns out with zsh you have to give the explicit path, you can’t just use ~/, so I added this to my .zshrc: export PATH=/Users/cagrimmett/.composer/vendor/bin:$PATH

    Once I loaded the profile with source ~/.zshrc, I was good to go. I linked my main projects folder so Valet knows where to look for projects, changed my wp-config.php files to point at my local mysql database instead of Homestead’s, then navigated to project-folder-name.test and was good to go!

    Valet runs at startup, so I don’t have to run cd ~/Homestead && vagrant up anymore, just brew services start mysql@5.7 if I need a database running (which you usually do for WordPress development.)

    I like that Valet makes it so easy to use different PHP versions. For example, to use 7.2, you go to your command line and type: valet use php@7.2

    I’m looking forward to never using Vagrant or VirtualBox again. Peace out

  • Doing a Digital Declutter

    Doing a Digital Declutter

    I recently read Cal Newport’s Digital Minimalism. I was more or less convinced before I picked the book up that I’m wasting too much time on social media and my ability to focus is becoming fragmented. I read this to hear his solution to this issue: Ruthlessly cutting out digital tools that don’t bring you value.

    I’d consider myself, in Newport’s parlance, a digital maximalist. I have accounts on every major platform, am an early-adopter of new digital platforms, social networks, and tools, and evangelize tools I find useful. My always connected.

    While I generally love this, I’ve noticed that my ability to focus for long periods of time and to sit and observe without needing a distraction (my phone) has diminished significantly. This is a problem. I value my observation abilities and don’t want to lose them. I also have so many things I want to do: Blog posts to write, spoons to carve, places to explore, etc.

    • How much am I missing by mindlessly scrolling through my phone?
    • What could I be doing instead of scrolling?
    • How much value am I getting from the scrolling anyway?

    Following Newport’s advice for doing a digital declutter, I took stock of what I think is causing me the most harm: Mindless scrolling. Here’s where it shows most:

    • Computer
      • Reddit
      • Twitter
      • Hacker news
      • Kottke
      • Daring fireball
    • Phone
      • Facebook
      • Twitter
      • Reddit
      • Instagram
      • Email
      • Slack
      • Hacker news
      • Kottke.org
      • Daring Fireball

    Only particular cycle that is bad for me is checking Slack, then my email, then Twitter, then Slack, then my email, then Twitter in an endless loop on my phone. I have no idea why I do this. Sometimes I’ll zone out and do this for 15 minutes straight without seeing anything new. Crazy.

    I saw that my friend Chris Johnson is doing a digital declutter, so I decided to join him.

    Here is my Digital Declutter plan for the next 30 days:

    Removing Distractions

    1. Use Focus to block all social media on my Mac.
    2. Use 1Blocker and Screen Time to block all social media in Safari on my iOS devices.
    3. Remove the native social media apps from iOS and macOS.
    4. Reorder my home screen to be productive apps: Writing and journaling apps, workout apps, reading apps, weather, and train/subway schedule apps.
    5. Move work-related and email apps to a folder on the farthest-right screen. The idea is that I need to have them for the workday, but I need to take a deliberate action to get to them. This keeps me from doing the Slack > Email > Slack > Email cycle.
    6. Using the Downtime feature in Screen Time to block access to everything but writing and journaling, iMessage, and Phone between 8pm and 7am.
    7. Removing everything except writing, journaling, coding, and drawing apps from my iPad. Keep the iPad a dedicated device for creation and reflection.
    8. As much as possible, leave my phone on the bookshelf by my desk. This means it is out of my line of site while I’m at my desk, but if I get an important text message, I’ll hear it.
    9. Turn off notifications for everything except Slack, Voxer, and iMessage. The essentials I can’t miss. Pare down the notifications in Slack to just direct messages and @mentions. Channel posts can wait.
    10. I’ll monitor my pickups and phone usage with Screen Time.

    Replacing with valuable activities

    1. Instead of scrolling through my phone immediately after I wake up, instead go work out first thing, then make my list of what I want to accomplish for the day.
    2. While at work, focus on work. Don’t take social media breaks. If I need a break, I can go for a walk or write.
    3. Spend my evenings cooking, writing, reading, and spending time with Amanda.
    4. Keep a running list of productive things I can do when I feel the urge to zone out and scroll:
      • Write (cooking blog, journal, main blog, Crash blog)
      • Carve
      • Sharpen my carving knives
      • Take photos
      • Read
      • Draw
      • Go for a walk
      • Listen to an audiobook and clean the house
      • Find a new recipe for my Cooking the Books challenge
      • Sleep
      • Spending time with friends
      • Exercise

    You’ll probably still see my post my blog posts on social media, but I’ll be doing that through Buffer so I stay away from the feeds. I still want those readers, you know.

    After 30 days I’ll reintroduce some things back into my life, but probably not all, and I’ll probably slim things down quite a bit. Probably some Instagram and Twitter, but restricted times. I’ll probably keep the main phone restrictions. We’ll see.

    I’m looking forward to this. I want my attention, observation, and creativity back. And along the way, my happiness.