PHP 8.1 was released on November 25, 2021 by the PHP Development team for public use. PHP is a very popular and powerful scripting and programming language for the Web. Most web applications and dynamic web pages are created in PHP. Either by using vanilla PHP coding or Frameworks powered by PHP. In this guide, we shall learn how you can install PHP 8.1 on Amazon Linux 2. Amazon Linux 2 is a Linux operating system from Amazon Web Services (AWS) designed to be secure, stable and to provide high performance.
New features in PHP 8.1?
Here is a summary of key features available in PHP 8.1 release.
- Enums – They are now added in PHP 8.1
- AVIF Image Format support – The PHP 8.1’s image processing and GD extension adds support for AVIF images.
- Readonly properties – Class properties can be marked as readonly hence can only be written once
- Never Return Type – A new return type hint called never is added in PHP 8.1
- Support for DNS-over-HTTPS (DoH)
- PHP 8.1 adds array_is_list as a built-in function
- Added support for Fibers – The low level mechanism to manage parallelism
- File Uploads with CURLStringFile – In PHP 8.1, PHP Curl extension now supports HTTP(S) requests with file uploads
- Addition of pure intersection types feature
- Define final Class Constants
- Explicit Octal Numeral Notation
- New fdatasync() and fsync() Functions
How To Install PHP 8.1 on Amazon Linux 2
We’ll use Remi YUM repositories to installPHP 8.1 on Amazon Linux 2. The versions of PHP available in default Amazon Linux 2 are much older. Remi repository is a free and stable YUM repository mainly for the PHP stack. It contains packages for the latest versions of PHP.
We’ll consider two methods of installingPHP 8.1 on Amazon Linux 2.
- Install PHP 8.1 as main PHP version (default version)
- Install PHP 8.1 alongside other PHP versions (e.g 8.0 and 7.4)
Install PHP 8.1 onAmazon Linux 2 alongside other PHP versions
If you use this method to installPHP 8.1 onAmazon Linux 2, you can run more than one version of PHP at the same time.
Let’s add REMI yum repository before we install PHP 8.1.
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
Confirm repository addition with the following commands:
$ sudo yum repolist
214 packages excluded due to repository priority protections
repo id repo name status
amzn2-core/2/x86_64 Amazon Linux 2 core repository 26801
amzn2extra-docker/2/x86_64 Amazon Extras repo for docker 55
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13481+208
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_64 4650+6
repolist: 44987
Enable Remi repository for PHP 8.1
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81
Finally install PHP 8.1 on Amazon Linux 2 system
sudo yum install php81
Sample output:
....
Dependencies Resolved
======================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing:
php81 x86_64 8.1-1.el7.remi remi-safe 2.9 k
Installing for dependencies:
audit-libs-python x86_64 2.8.1-3.amzn2.1 amzn2-core 79 k
checkpolicy x86_64 2.5-6.amzn2 amzn2-core 294 k
environment-modules x86_64 3.2.10-10.amzn2.0.2 amzn2-core 107 k
libX11 x86_64 1.6.7-3.amzn2.0.2 amzn2-core 606 k
libX11-common noarch 1.6.7-3.amzn2.0.2 amzn2-core 165 k
libXau x86_64 1.0.8-2.1.amzn2.0.2 amzn2-core 29 k
libcgroup x86_64 0.41-21.amzn2 amzn2-core 66 k
libselinux-python x86_64 2.5-12.amzn2.0.2 amzn2-core 237 k
libsemanage-python x86_64 2.5-11.amzn2 amzn2-core 115 k
libxcb x86_64 1.12-1.amzn2.0.2 amzn2-core 216 k
ncurses-compat-libs x86_64 6.0-8.20170212.amzn2.1.3 amzn2-core 308 k
php81-php-cli x86_64 8.1.0-1.el7.remi remi-safe 3.9 M
php81-php-common x86_64 8.1.0-1.el7.remi remi-safe 710 k
php81-runtime x86_64 8.1-1.el7.remi remi-safe 1.1 M
policycoreutils-python x86_64 2.5-22.amzn2 amzn2-core 454 k
python-IPy noarch 0.75-6.amzn2.0.1 amzn2-core 32 k
setools-libs x86_64 3.3.8-2.amzn2.0.2 amzn2-core 618 k
tcl x86_64 1:8.5.13-8.amzn2.0.2 amzn2-core 1.9 M
Transaction Summary
======================================================================================================================================================================================================
Install 1 Package (+18 Dependent packages)
Total download size: 11 M
Installed size: 39 M
Is this ok [y/d/N]: y
Checking version of PHP 8.1 installed:
$ php81 --version
PHP 8.1.0 (cli) (built: Nov 23 2021 18:56:11) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
Configuration files for PHP are located in /etc/opt/remi/php81/
directory
$ ls -1 /etc/opt/remi/php81/
X11
opt
php.d
php.ini
pki
pm
skel
sysconfig
xdg
xinetd.d
Install PHP 8.1 extensions on Amazon Linux 2
To install any PHP 8.1 extension, use command syntax below:
sudo yum install php81-php-xxx
See below example:
sudo yum install php81-php-{cli,fpm,mysqlnd,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,ldap}
Agree to installation prompt:
...
Dependencies Resolved
======================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing:
php81-php-bcmath x86_64 8.1.0-1.el7.remi remi-safe 86 k
php81-php-devel x86_64 8.1.0-1.el7.remi remi-safe 832 k
php81-php-fpm x86_64 8.1.0-1.el7.remi remi-safe 2.0 M
php81-php-gd x86_64 8.1.0-1.el7.remi remi-safe 91 k
php81-php-ldap x86_64 8.1.0-1.el7.remi remi-safe 93 k
php81-php-mbstring x86_64 8.1.0-1.el7.remi remi-safe 483 k
php81-php-mysqlnd x86_64 8.1.0-1.el7.remi remi-safe 190 k
php81-php-opcache x86_64 8.1.0-1.el7.remi remi-safe 414 k
php81-php-pear noarch 1:1.10.13-1.el7.remi remi-safe 364 k
php81-php-xml x86_64 8.1.0-1.el7.remi remi-safe 184 k
Installing for dependencies:
autoconf noarch 2.69-11.amzn2 amzn2-core 701 k
automake noarch 1.13.4-3.1.amzn2 amzn2-core 679 k
cpp x86_64 7.3.1-13.amzn2 amzn2-core 9.2 M
dejavu-fonts-common noarch 2.33-6.amzn2 amzn2-core 64 k
dejavu-sans-fonts noarch 2.33-6.amzn2 amzn2-core 1.4 M
fontconfig x86_64 2.13.0-4.3.amzn2 amzn2-core 253 k
fontpackages-filesystem noarch 1.44-8.amzn2 amzn2-core 10 k
fribidi x86_64 1.0.2-1.amzn2.1 amzn2-core 79 k
gcc x86_64 7.3.1-13.amzn2 amzn2-core 22 M
gcc-c++ x86_64 7.3.1-13.amzn2 amzn2-core 13 M
gd-last x86_64 2.3.3-2.el7.remi remi-safe 138 k
glibc-devel x86_64 2.26-56.amzn2 amzn2-core 994 k
glibc-headers x86_64 2.26-56.amzn2 amzn2-core 514 k
graphite2 x86_64 1.3.10-1.amzn2.0.2 amzn2-core 115 k
harfbuzz x86_64 1.7.5-2.amzn2 amzn2-core 279 k
kernel-headers x86_64 4.14.252-195.483.amzn2 amzn2-core 1.2 M
keyutils-libs-devel x86_64 1.5.8-3.amzn2.0.2 amzn2-core 37 k
krb5-devel x86_64 1.15.1-37.amzn2.2.2 amzn2-core 272 k
libXpm x86_64 3.5.12-1.amzn2.0.2 amzn2-core 57 k
libatomic x86_64 7.3.1-13.amzn2 amzn2-core 46 k
libcilkrts x86_64 7.3.1-13.amzn2 amzn2-core 85 k
libcom_err-devel x86_64 1.42.9-19.amzn2 amzn2-core 32 k
libitm x86_64 7.3.1-13.amzn2 amzn2-core 84 k
libkadm5 x86_64 1.15.1-37.amzn2.2.2 amzn2-core 179 k
libmpc x86_64 1.0.1-3.amzn2.0.2 amzn2-core 52 k
libmpx x86_64 7.3.1-13.amzn2 amzn2-core 51 k
libquadmath x86_64 7.3.1-13.amzn2 amzn2-core 189 k
libraqm x86_64 0.7.0-4.el7 epel 15 k
libsanitizer x86_64 7.3.1-13.amzn2 amzn2-core 641 k
libselinux-devel x86_64 2.5-12.amzn2.0.2 amzn2-core 187 k
libsepol-devel x86_64 2.5-8.1.amzn2.0.2 amzn2-core 77 k
libtool x86_64 2.4.2-22.2.amzn2.0.2 amzn2-core 588 k
libverto-devel x86_64 0.2.5-4.amzn2.0.2 amzn2-core 12 k
libwebp7 x86_64 1.0.3-1.el7.remi remi-safe 266 k
libxml2-devel x86_64 2.9.1-6.amzn2.5.4 amzn2-core 1.1 M
libxslt x86_64 1.1.28-6.amzn2 amzn2-core 240 k
m4 x86_64 1.4.16-10.amzn2.0.2 amzn2-core 256 k
mpfr x86_64 3.1.1-4.amzn2.0.2 amzn2-core 208 k
oniguruma5php x86_64 6.9.7.1-1.el7.remi remi-safe 205 k
openssl-devel x86_64 1:1.0.2k-19.amzn2.0.10 amzn2-core 1.5 M
pcre-devel x86_64 8.32-17.amzn2.0.2 amzn2-core 480 k
perl-Data-Dumper x86_64 2.145-3.amzn2.0.2 amzn2-core 48 k
perl-Test-Harness noarch 3.28-3.amzn2 amzn2-core 302 k
perl-Thread-Queue noarch 3.02-2.amzn2 amzn2-core 17 k
php81-php-pdo x86_64 8.1.0-1.el7.remi remi-safe 131 k
php81-php-process x86_64 8.1.0-1.el7.remi remi-safe 90 k
xz-devel x86_64 5.2.2-1.amzn2.0.2 amzn2-core 46 k
zlib-devel x86_64 1.2.7-18.amzn2 amzn2-core 50 k
Transaction Summary
======================================================================================================================================================================================================
Install 10 Packages (+48 Dependent packages)
Total download size: 62 M
Installed size: 187 M
Is this ok [y/d/N]: y
Use below commands list all PHP modules
$ php81 --modules
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
You now have PHP 8.1 installed on your Amazon Linux 2 system. We have provided links to important PHP websites and Forums below: