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:
....
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:
...
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:
- Ideas to work on includes ideas that people might want to work on
- Google Summer of Code
- Contacts for certain supported platforms
- Developer Summits
- PHP User Group Information