Update PHP version on Amazon EC2 to PHP 7.3
First, check current PHP version.
php -versionAs the installed version is outdated, an upgrade is necessary. The tool yum is used for this. Update the yum package repository information.
sudo yum updateInstall 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 php73Check PHP version.
php -version# Still 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 phpGet Makitril G’s stories in your inbox
Join Medium for free to get updates from this writer.
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# 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-bcmathInstall 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-pdoRestart HTTPD is now running PHP 7.3.







