How to Install PHP 8.0 on AlmaLinux 8

PHP 8.0 is a significant update of the PHP language released on November 26, 2020, a giant leap forward from the existing PHP 7.4 release. The new PHP contains many new features and optimizations, including named arguments, union types, attributes, constructor property promotion, match expression, null safe operators, JIT and improvements in the type system, error handling, and consistency.

In the following tutorial, you will learn how to install PHP 8.0 on AlmaLinux.

Prerequisites

  • Recommended OS: AlmaLinux 8.
  • User account: A user account with sudo privilages or root access (su command).

Updating Operating System

Update your AlmaLinux operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status. To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@localhost ~]$ sudo whoami
root

If you have not set up a sudo user account and would like to, visit our tutorial on How to Add a User to Sudoers on AlmaLinux.

To use the root account, use the following command with the root password to log in.

su

Import PHP 8.0 Repository

Currently, PHP 8.0 is not featured in AlmaLinuxs AppStream, given it’s still relatively new and hasn’t filtered down the chain in RHEL’s repositories yet. However, you can install PHP from (Remi) repository, a free-to-use third-party repository that deploys the latest PHP 8.0 and includes the incoming PHP 8.1.

The first task is to install the (EPEL) repository, which stands for (Extra Packages for Enterprise Linux). For newer users to RHEL family and AlmaLinux, EPEL contains the most commonly used software packages for Enterprise Linux.

To install EPEL, use the following (dnf) terminal command:

sudo dnf install epel-release

Example output:

How to Install PHP 8.0 on AlmaLinux 8

Type (Y), then press (ENTER KEY) to proceed.

Now that you have added the EPEL repository, enable (Remi repository) with the following:

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Example output:

How to Install PHP 8.0 on AlmaLinux 8

Type (Y), then press (ENTER KEY) to proceed.

Next, use the (dnf) command to update your repository list:

sudo dnf update

You will notice a query in your terminal about importing the (GPG key) for the Remi repository as below:

How to Install PHP 8.0 on AlmaLinux 8

Type (Y), then press (ENTER KEY) to proceed.

Note that you will be prompted two more times to type (Y) two more times to import more GPG keys. This is fine to do.

Next, you will be prompted to upgrade the EPEL release:

How to Install PHP 8.0 on AlmaLinux 8

Type (Y), then press (ENTER KEY) to proceed.

Your EPEL repository is now up to date, and you are ready to proceed to the next part of the tutorial.

Enabling PHP 8.0 (Remi) Repository

PHP 7.2 is the default PHP choice for standard installation on Rhel/Alma Linux with Remi’s repository. A quick tip is to use the (list.php) command to see the options available and the default. The following command can do this:

sudo dnf module list php

You will get the following output as below. Note the (d) tag for default PHP to be installed:

How to Install PHP 8.0 on AlmaLinux 8

As you can see above, the (d) tag is next to PHP 7.2, which you are going to need to reset and change to proceed to install PHP 8.0 on AlmaLinux. To reset the PHP list is easy with the following command:

sudo dnf module list reset php

Next, enable PHP 8.0 with the following command:

sudo dnf module enable php:remi-8.0 -y

Example output once complete:

How to Install PHP 8.0 on AlmaLinux 8

Install PHP 8.0

Now that you have added the Remi PHP repository and enabled PHP 8.0 to be the default version on your AlmaLinux system, you can install PHP 8.0 with the following command:

sudo dnf install php

Example output:

How to Install PHP 8.0 on AlmaLinux 8

Type (Y), then press (ENTER KEY) to proceed.

If you would like to install the most commonly used extensions for PHP 8.0, use the following command:

sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml

Note, remove the options you do not want this is optional.

Example output:

How to Install PHP 8.0 on AlmaLinux 8

Type (Y), then press (ENTER KEY) to proceed.

Now that you have installed PHP 8.0 and the extensions check the version with the following command:

php -v

Example output:

PHP 8.0.10 (cli) (built: Aug 24 2021 15:40:40) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies

PHP-FPM is not enabled by default on AlmaLinux. To enable PHP-FPM on system boot and to kick start it off, use the following (systemctl) command:

sudo systemctl enable php-fpm && sudo systemctl start php-fpm

Example of successfully enabling (symlink):

Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

Now, as before with checking the status of the other requirements in your LEMP installation, use the following (systemctl) terminal command to check the status to make sure everything is working:

systemctl status php-fpm

If no errors are present, you should get the following output:

How to Install PHP 8.0 on AlmaLinux 8

PHP-FPM Installations of PHP 8.0

Unlike PHP-FPM installations on Debian/Ubuntu that use the (www-data) user, this isn’t the case with RHEL family installations. By default on AlmaLinux, the PHP-FPM service is designed to be run (Apache) user, which is incorrect since we are using Nginx, and this needed to be corrected.

Firstly, open following (www.conf) configuration file:

sudo nano /etc/php-fpm.d/www.conf

Next, replace the (Apache) user and group with the (Nginx) user and group:

How to Install LEMP Stack on AlmaLinux 8

To save, press (CTRL+O) then exit (CTRL+X).

Now you will too reload or restart your PHP-FPM service:

sudo systemctl restart php-fpm

Comments and Conclusion

In the tutorial, you have learned about the (EPEL) repository and (Remi) repository and how to add them to your AlmaLinux 8 operating system, along with installing PHP 8.0 from the Remi repository.

Overall, PHP 8.0 is now starting to become pretty standard everywhere. With the development of the upcoming PHP 8.1, more developers are now making their web applications PHP 8 friendly, including the giant CMS WordPress with more theme and plugin devs racing to get PHP 8.0 supported given the advantages 8 has in security and speed compared the 7 series.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!