A client’s machine installed with PHP 7.4 needs to be upgraded to PHP 8.0 sooner as the former is reaching “End of Life” support (until November 28, 2022). Here’s a link about it: https://www.php.net/supported-versions.php
These are the steps made to complete the upgrade procedure:
#1. On the client’s Amazon Linux 2 Virtual Machine, list the PHP versions available.
[root@ip-172-31-84-24 html]# amazon-linux-extras | grep php
42 php7.4=latest enabled [ =stable ]
_ php8.0 available [ =stable ]
#2. Disable php 7.4.
[root@ip-172-31-84-24 html]# amazon-linux-extras disable php7.4
Beware that disabling topics is not supported after they are installed.
. . . .
. . . .
42 php7.4 available [ =stable ]
. . . .
51 php8.0 available [ =stable ]
. . . .
#3. Check PHP list again.
[root@ip-172-31-84-24 html]# amazon-linux-extras |grep php
42 php7.4 available [ =stable ]
51 php8.0 available [ =stable ]
#4. Enable PHP 8.0.
[root@ip-172-31-84-24 html]# amazon-linux-extras enable php8.0
. . . .
41 postgresql11 available [ =11 =stable ]
_ php7.4 available [ =stable ]
. . . .
51 php8.0=latest enabled [ =stable ]
. . . .
Now you can install:
# yum clean metadata
# yum install php-cli php-pdo php-fpm php-mysqlnd
#5. Clean metadata.
[root@ip-172-31-84-24 html]# yum clean metadata
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel amzn2extra-kernel-5.10 amzn2extra-php8.0 epel epel-debuginfo epel-source epel-testing epel-testing-debuginfo epel-testing-source
52 metadata files removed
20 sqlite files removed
0 metadata files removed
#6. Now check available php installation.
[root@ip-172-31-84-24 html]# yum info php
. . . .
232 packages excluded due to repository priority protections
. . . .
Available Packages
Name : php
Arch : x86_64
Version : 8.0.20
Release : 1.amzn2
Size : 3.3 M
Repo : amzn2extra-php8.0/2/x86_64
#7. Running the command in #4 as suggested gives an error
[root@ip-172-31-84-24 html]# yum install php-cli php-pdo php-fpm php-mysqlnd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
232 packages excluded due to repository priority protections
Resolving Dependencies
–> Running transaction check
. . . .
–> Processing Dependency: php-common(x86-64) = 8.0.20-1.amzn2 for package: php-cli-8.0.20-1.amzn2.x86_64
. . . .
–> Finished Dependency Resolution
Error: Package: php-json-7.4.26-1.amzn2.x86_64 (@amzn2extra-php7.4)
Requires: php-common(x86-64) = 7.4.26-1.amzn2
Removing: php-common-7.4.26-1.amzn2.x86_64 (@amzn2extra-php7.4)
. . . .
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
#8. Remove the php-json* package
[root@ip-172-31-84-24 html]# yum remove php-json
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
–> Running transaction check
—> Package php-json.x86_64 0:7.4.26-1.amzn2 will be erased
–> Processing Dependency: php-json(x86-64) = 7.4.26-1.amzn2 for package: php-common-7.4.26-1.amzn2.x86_64
–> Running transaction check
. . . .
. . . .
–> Finished Dependency Resolution
Removed:
php-json.x86_64 0:7.4.26-1.amzn2
Dependency Removed:
php-cli.x86_64 0:7.4.26-1.amzn2 php-common.x86_64 0:7.4.26-1.amzn2 php-fpm.x86_64 0:7.4.26-1.amzn2 php-mbstring.x86_64 0:7.4.26-1.amzn2 php-mysqlnd.x86_64 0:7.4.26-1.amzn2 php-pdo.x86_64 0:7.4.26-1.amzn2
php-xml.x86_64 0:7.4.26-1.amzn2
Complete!
#9. Install PHP and other dependencies
[root@ip-172-31-84-24 html]# yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
232 packages excluded due to repository priority protections
Resolving Dependencies
–> Running transaction check
. . . .
Installed:
php.x86_64 0:8.0.20-1.amzn2 php-bcmath.x86_64 0:8.0.20-1.amzn2 php-cli.x86_64 0:8.0.20-1.amzn2 php-common.x86_64 0:8.0.20-1.amzn2 php-fpm.x86_64 0:8.0.20-1.amzn2 php-gd.x86_64 0:8.0.20-1.amzn2
php-intl.x86_64 0:8.0.20-1.amzn2 php-mbstring.x86_64 0:8.0.20-1.amzn2 php-mysqlnd.x86_64 0:8.0.20-1.amzn2 php-pear.noarch 1:1.10.12-9.amzn2 php-xml.x86_64 0:8.0.20-1.amzn2
Dependency Installed:
php-pdo.x86_64 0:8.0.20-1.amzn2 php-process.x86_64 0:8.0.20-1.amzn2
Complete!
#10. A continuation the output in #9 installation message. Just disregard this.
php-json is available in Amazon Linux Extra topic “php7.4”
To use, run
# sudo amazon-linux-extras install php7.4
#11. Now check PHP version
[root@ip-172-31-84-24 ~]# php -v
PHP 8.0.20 (cli) (built: Jun 23 2022 20:34:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.20, Copyright (c) Zend Technologies