Update PHP version on Amazon EC2

It was time to update the PHP version on my WordPress server. WordPress gave me warnings; the site health plugin gave me a warning. Plugins gave me warnings. PHP, IT news sites, the internet, warnings everywhere.

I knew that my PHP version was very old. But still supported. At least until beginning of 2019. When I configured the server for the first time several years ago, the installed PHP version was already not the latest. It was what yum install php gave me. Updating software is crucial, so I decided to finally touch my running system.

WordPress provides a site explaining how to update your PHP version. The update process in the documentation goes like: write an email to your hoster. Or: Not working in my case. For those that want to know how to update PHP on a Amazon AMI EC2 instance, here are the stops and my lessons learned.


First, do a backup. Update WordPress and the plugins. Check that the plugins are compatible with PHP 7.2

  • Backup: See my blog on how to create a snapshot of a EC2 instance.
  • Update WordPress and plugins: Easy: just do as always and keep it up-to-date.
  • Check plugins for compatibility: A plugin is available to check the installed plugins and files for compatibility with PHP 7.x. Install and activate it and run a test.

The PHP Compatibility plugin is started from the WP Admin site. Hint: in my case, the plugin worked fine, but also crashed the server. After running it and saving the results, uninstall it.

This gives as an output an evaluation of the plugins and their compatibility status.


Next step is to update PHP. Use the package manager for this. I’ll split the installation process in two parts: PHP and the additional packages.

sudo yum update
sudo yum install php72
sudo yum install php72-opcache php72-mysqlfnd php72-gd php72-pecl-imagick php72-bcmath

Result installation PHP 7.2

Result Installation of additional PHP packages

Activate PHP

After installing PHP 7.2 it must be activated. The old PHP version is still the default one, meaning that calling php is not calling php 7.2. To change the paths, run alternative. It will show the available alternatives and asks which one you want to use. I am going to use php 7.2, so the input here was 2.

alternatives --config php

php -version

Now PHP 7.2 is installed and activated. After restarting Apache WordPress will run on a newer PHP version.

Let the world know

Update WordPress and W3 total cache plugin error

WordPress is easy to update … if everything works. I updated my WordPress version many times without problems, patches are installed automatically. Only minor versions I do install manually. Last time I updated, an error happened. Luckily, not for my users, the public site was up and running. My admin site (wp-admin) was broken. To be more precise: the update was not completed. While loading the update page to trigger the DB update, I got an error message: not found.

Looking at the web server log, I could see that something went wrong with a PHP call:

PHP Fatal error:  Call to undefined function wp_cache_get() in /var/…/wp-includes/option.php on line 1123

I use a plugin called W3 total cache for speeding up the loading of my site. My idea was to uninstall this plugin and see if it works again. Problem: how to uninstall a WordPress plugin without being able to log in? During running an update? Of course, if you do not try, you do not learn. First step was to do a backup (yeah …). Next step was: delete the plugin manually. This I did by deleting/moving the W3tc related files.

  • /wp-content/plugins/w3-total-cache
  • advanced-cache.php
  • db.php

After this I accessed /wp-admin again and could complete the WordPress upgrade of the database. The W3-total-cache plugin was not installed anymore, so I reinstalled it.

Why reinstalling a broken plugin? The plugin is (as of the writing of this text) not compatible with my WordPress version. Therefore, I only install it to remove the plugin. I did so manually and to keep my WordPress installation not a total mess, I want to delete the plugin the official way. In the dashboard > Plugins > Installed Plugins the plugin is listed. Instead of activating it, I am going to delete it.


Next step is to install another cache plugin.

Let the world know