Update PHP version on Amazon EC2 to PHP 7.3

Published by Tobias Hofmann on

4 min read

In November 2019 I wrote about how to update the PHP version on a Amazon AWS EC2 Linux instance to PHP 7.2. At that time, PHP 7.3 was already a year available. As PHP 7.2 is out of support since November 2020, the next available release on EC2 AMI Linux is 7.3. Version 7.4 is also available, but you must do a little bit more than just upgrading your Linux. To show that you can easily upgrade to PHP 7.3, I’ll show the steps to do so here first, and in a later blog show the upgrade to PHP 7.4.

Preparations

First, check current PHP version.

php -version
Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Result: Version 7.2.34 is installed

As the installed version is outdated, an upgrade is necessary. The tool yum is used for this. Update the yum package repository information.

sudo yum update

Installation

Install PHP 7.3. Be aware that below command will only install base PHP 7.3. Additional packages needed, e.g. for WordPress, are not included. Also, while PHP 7.3 is going to be installed, it won’t be activated.

yum install php73
Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Check PHP version.

php -version
Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Result: Version 7.2.34 is installed.

Activation

As stated above, yum will install PHP 7.3, but not activate it. While it is available in the system, it is not in the path. To activate it, configure it as the preferred alternative.

sudo alternatives --config php
Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

The command will show the installed PHP version and which one is the default, marked with *. To make PHP 7.3 the default one, enter the corresponding number. In my case: 3. Now run php again and check the reported version. It must be 7.3.x.

php -version
Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Result: Congratulations. EC2 Linux is now using PHP version 7.3.23.

Additional packages

Additional PHP 7.3 packages, can also be installed via yum. If you know that you need them, you can install them together with the previous command above.

sudo yum install php73-gd php73-opcache php73-pecl-imagick php73-bcmath

Install MySQL extension

In case you are running WordPress with MySQL as a backend, you do now have a problem. Restart HTTP and access WordPress. An error message will be shown saying that the MySQL extension is missing. To be able to connect to the database, additional components need to be installed. Here is a difference compared to my blog on upgrading to PHP 7.2. Be aware that the MySQL extension changed its name. You need to install packages php73-mysqlnd and php73-pdo.

sudo yum install php73-mysqlnd php73-pdo
Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Restart HTTPD and WordPress is now running PHP 7.3.

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Next: upgrading to PHP 7.4.

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung
Let the world know

Tobias Hofmann

Doing stuff with SAP since 1998. Open, web, UX, cloud. I am not a Basis guy, but very knowledgeable about Basis stuff, as it's the foundation of everything I do (DevOps). Performance is king, and unit tests is something I actually do. Developing HTML5 apps when HTML5 wasn't around. HCP/SCP user since 2012, NetWeaver since 2002, ABAP since 1998.

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.