PHP 8.0 is a major 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 Rocky Linux 8.
- Recommended OS: Rocky Linux 8.+
- User account: A user account with sudo or root access.
Installing PHP 8.0 Repository
Currently, PHP 8.0 is not featured in Rocky Linux’s AppStream, given it’s still quite 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 updates to PHP 8.0 and includes the new 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 and Rocky Linux, 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, type (Y), and enter 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
Again as example output, type (Y) and enter 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:
Type (Y) to proceed with importing the GPG key and updating your repositories. Note, you will be prompt 2 more times to type (Y) to import more GPG keys. This is fine to do.
Enabling PHP 8.0 (Remi) Repository
With Remi’s repository, PHP 7.2 is the default PHP choice for standard installation on Rhel/Rocky Linux. A quick tip is to use the (list php) command to see what options are 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:
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 Rocky Linux. 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:
Installing PHP 8.0
Now that you have added the Remi PHP repository and enabled PHP 8.0 to be the default version on your Rocky Linux system, you can install PHP 8.0 with the following command:
sudo dnf install php
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. For the guide, we installed the entire lot as below:
Now that you have installed PHP 8.0 and the extensions check the version with the following command:
Example output below, remember this will change in time:
Congratulations, you have installed PHP 8.0 on Rocky Linux.
Comments and Conclusion
In the tutorial, you have learnt about the (EPEL) repository and (Remi) repository and how to add them to your Rocky Linux system, along with installing PHP 8.0 from those repositories. Overall, PHP 8.0 is now starting to become pretty standard everywhere, and 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.
However, you should only install PHP 8.0 if you know your software supports it, as it will cause issues with your applications, so be sure to check. If you know how to install Rocky Linux 8, check out our guide on how to install Rocky Linux 8.