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
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
Now PHP 7.2 is installed and activated. After restarting Apache WordPress will run on a newer PHP version.