I want to upgrade PHP on Amazon Lightsail.
Resolution
You can update PHP in the following operating systems (OS) that run on Lightsail:
- Bitnami for WordPress and LAMP
- Amazon Linux 2023
- Amazon Linux 2
- Ubuntu 22.04 LTS and 20.04 LTS
- Debian 12 and 11
- CentOS 9
Important: Before you update PHP, make sure that your code is compatible with the version that you want to upgrade to. It's a best practice to back up your instance before you update PHP. For more information, see Snapshots in Amazon Lightsail.
To update PHP, complete the steps for the OS that runs on your instance.
Bitnami for WordPress and LAMP
To update PHP in Bitnami for WordPress and LAMP, launch a new WordPress or LAMP instance, and then migrate the data from your current website to the new instance. For more information, see Migrate data from one WordPress instance to another on the Bitnami website.
Amazon Linux 2023
To upgrade the minor version of PHP to its latest update, run the following command:
$ sudo yum upgrade php -y
To upgrade PHP to the latest major version, run the following commands:
$ sudo yum remove php\* -y
$ sudo yum clean all
$ sudo yum install php -y
Amazon Linux 2
To upgrade to PHP 8.1 and 8.2, use the Extras Library:
$ sudo amazon-linux-extras | grep php
66 †php8.1 available [ =stable ]
68 †php8.2 available [ =stable ]
To upgrade the minor version of PHP to its latest update, complete the following steps:
-
Turn off the current version of PHP:
$ sudo amazon-linux-extras disable example-php
$ sudo yum remove php*
$ sudo yum clean all
Note: Replace example-PHP with the current minor version of PHP. For example, to turn off PHP 8.1, replace example-PHP with php8.1.
-
Upgrade PHP:
$ sudo yum upgrade php -y
To upgrade PHP to the latest major version, complete the following steps:
-
Turn on PHP topics.
$ sudo amazon-linux-extras enable example-php
Note: Replace example-PHP with the current major version of PHP.
-
Install the PHP packages:
$ sudo yum clean metadata
$ sudo install php-cli php-pdo php-fpm php-json php-mysqlnd
Ubuntu 22.04 LTS and 20.04 LTS
To upgrade PHP to the latest version, run the following command:
$ sudo apt install php
Debian 12 and 11
Important: It's a best practice to use Debian 11 or 12. Debian 10 is no longer supported.
To upgrade PHP to the latest version, run the following command:
$ sudo apt install php
CentOS 9
Important: It's a best practice to use CentOS Stream 9. CentOS 7 is no longer supported.
To upgrade PHP to the latest version, complete the following steps:
-
List your instance's versions of PHP:
$ sudo dnf module list php
-
If the latest version of PHP isn't installed and activated, then reset PHP and activate the latest version:
$ sudo dnf module reset -y php
$ sudo dnf module -y enable example-php
Note: Replace example-php with the current major version of PHP.
-
Install the latest version:
$ sudo dnf module -y install php