Views: 40
0 0
Read Time:6 Minute, 19 Second

The PHP team is yet to officially release PHP 8.1 on November 25, 2021. Usually there is a 6 months pre-release phase before the GA release of PHP. As most of you know, PHP is a widely used scripting language. It is mostly used to create web applications and dynamic web pages. In this guide, we shall cover the installation of PHP 8.1 on CentOS 7|RHEL 7.

PHP 8.1 is an update to version 8.0 which was a major release from its predecessor – PHP 7.x. Some of the most powerful content management systems such as Joomla, Drupal, WordPress, OpenCart, Magento, OctoberCMS, and Joomla are created in PHP. PHP 8.1 ships with a set of new features and improvements. Install PHP 8.1 on CentOS 7|RHEL 7 and start exploring its new features and deprecations.

What’s new in PHP 8.1?

  • Enums – They are now added in PHP 8.1
  • 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)
  • AVIF Image Format support – The PHP 8.1’s image processing and GD extension adds support for AVIF images.
  • 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
  • PHP 8.1 adds array_is_list as a built-in function
  • Explicit Octal Numeral Notation
  • New fdatasync() and fsync() Functions
  • Define final Class Constants
  • Among many other new features and deprecations

Install PHP 8.1 on CentOS 7|RHEL 7

Since the default YUM repositories in CentOS 7|RHEL 7 doesn’t contain PHP 8.1 packages, we’ll use REMI repository to install 8.1 on CentOS 7|RHEL 7.

You can either;

  1. Install PHP 8.1 as main PHP version (default version)
  2. Install PHP 8.1 alongside other PHP versions (e.g 8.0 and 7.4)

In this method you’ll have a single release of PHP as default in your system. This assumes the application has been tested and certified to be running on PHP 8.1. It is not recommended to have Beta and RC releases of PHP as default in a production environments.

If you prefer having PHP 8.1 as the default version on yourCentOS 7|RHEL 7 then perform the installation with the commands below:

CentOS 7:

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
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81
sudo yum repolist
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,redis,memcache}

RHEL 7:

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install yum-utils
sudo subscription-manager repos --enable=rhel-7-server-optional-rpms
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81
sudo yum repolist
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,redis,memcache}

Install PHP 8.1 extensions on CentOS 7 | RHEL 7

To install any PHP 8.1 extension, use command syntax below:

sudo yum install php-xxx

Use the following commands to check PHP version:

$ php --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

For early releases of PHP programming language it is viable to install alongside other stable GA releases. This allows you to test the new features without breaking your current running applications.

Install PHP 8.1 alongside other PHP versions on CentOS 7 | RHEL 7

### CentOS 7 ###
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
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-safe
sudo yum repolist
sudo yum install php81
### RHEL 7 ###
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install yum-utils
sudo subscription-manager repos --enable=rhel-7-server-optional-rpms
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-safe
sudo yum repolist
sudo yum install php81

Use the command below to install additional PHP extensions:

sudo yum install php81-php-xxx

See below example:

sudo yum install php81-php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache}

Agree to installation prompt:

....
====================================================================================================================================================================================================== Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing: php81-php-bcmath x86_64 8.1.0~rc6-1.el7.remi remi-safe 86 k php81-php-devel x86_64 8.1.0~rc6-1.el7.remi remi-safe 831 k php81-php-fpm x86_64 8.1.0~rc6-1.el7.remi remi-safe 2.0 M php81-php-gd x86_64 8.1.0~rc6-1.el7.remi remi-safe 91 k php81-php-mbstring x86_64 8.1.0~rc6-1.el7.remi remi-safe 483 k php81-php-mysqlnd x86_64 8.1.0~rc6-1.el7.remi remi-safe 190 k php81-php-opcache x86_64 8.1.0~rc6-1.el7.remi remi-safe 414 k php81-php-pear noarch 1:1.10.13-1.el7.remi remi-safe 364 k php81-php-pecl-zip x86_64 1.20.0-1.el7.remi remi-safe 55 k php81-php-xml x86_64 8.1.0~rc6-1.el7.remi remi-safe 184 k
Installing for dependencies: php81-php-pdo x86_64 8.1.0~rc6-1.el7.remi remi-safe 131 k php81-php-process x86_64 8.1.0~rc6-1.el7.remi remi-safe 90 k
Transaction Summary
======================================================================================================================================================================================================
Install 10 Packages (+2 Dependent packages)
Total download size: 4.9 M
Installed size: 20 M
Is this ok [y/d/N]: y

Use below commands to check PHP 8 version and available extensions

$ 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 with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
$ 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

If you followed our guide step-by-step, you should have PHP 8.1 installed on your CentOS 7|RHEL 7 system. Important PHP forums and websites: