Table of Contents[Hide][Show]
Are you looking to upgrade your PHP version to the latest PHP 8 on CentOS 7? In this guide, we will walk you through how to install PHP 8 on CentOS 7 | RHEL 8.
By following the step-by-step instructions, you can enable the necessary repositories, such as EPEL and REMI, and easily install PHP 8 on your CentOS 7 system.
PHP 8 brings numerous performance improvements, new features, and enhanced security, making it an ideal choice for your web development projects. So, let’s dive in and explore how you can harness the power of PHP 8 on CentOS 7.
Before that let’s have a look at some of the most notable new features in PHP 8:
Features in PHP 8
Enums: Enums are a new type that allows you to represent a set of named constants. They are a useful way to represent enumerated values, such as the days of the week or the months of the year.
Fibers: Fibers are a new lightweight concurrency primitive that allows you to run multiple concurrent tasks within a single PHP process. They are a more efficient way to implement asynchronous code than using traditional threads.
Readonly properties: Readonly properties are a new type of property that can only be assigned a value once. They are a useful way to prevent accidental changes to important data.
Intersection types: Intersection types are a new type that allows you to combine two or more other types. They are a useful way to express the fact that a value must be of one type or another.
Never return type: The never return type is a new type that represents a function that never returns. It is useful to indicate that a function will always throw an exception or reach the end of its code without returning it.
First-class callable syntax: First-class callable syntax is a new way to represent callable objects. It is a more concise and expressive way to write code that uses callable objects.
Other new features: In addition to the features listed above, PHP 8.1 also includes a number of other new features, such as:
- Improved support for AVIF images
- Support for DNS-over-HTTPS (DoH)
- Improved performance with inheritance cache
- Deprecations of some old features
PHP 8 is a significant update that introduces many new features and improvements.
- A user account with sudo privileges
- Access to a command line interface or terminal window
Before We Begin
Login to the server
To login to a CentOS 7 system using a sudo privileged account, you can follow these steps:
Open a terminal on your local machine.
Use the ssh command to establish a secure shell connection to the CentOS 7 system. Replace
with the username of your sudo privileged account and
with the IP address or hostname of the CentOS 8 system.
Enter the password for the sudo privileged account when prompted. Note that while typing the password, you won’t see any characters on the screen.
Once you are logged in successfully, execute commands with
sudo privileges by prefixing them with the sudo command. For example:
You will be prompted to enter the password for the sudo privileged account again. After entering the password correctly, the command will be executed with the necessary privileges.
Remember to replace
with the actual username and IP address/hostname of your CentOS 7 system.
To upgrade the current packages on CentOS 7, you can use the
dnf command, which is the package manager for CentOS 7. Follow these steps:
Update the packages
Update the packages by running the following command:
sudo dnf check-update
This command will check for any available updates without actually performing the upgrade.
If there are updates available, you can proceed with the upgrade by running the following command:
sudo dnf upgrade
This command will upgrade all the packages to their latest versions. You may be prompted to confirm the download and installation of the packages. Press
y and then Enter to proceed.
Alternatively, you can use the
-y flag to automatically answer yes to all prompts:
sudo dnf upgrade -y
This will skip the confirmation step and automatically upgrade the packages.
Wait for the upgrade process to complete. It may take some time depending on the number of packages being upgraded and the speed of your internet connection.
Once the upgrade is finished, you will see a summary of the packages that have been upgraded.
By executing these steps, you will upgrade the current packages on your CentOS 7 system to their latest versions.
How To Install PHP 8 on CentOS 7 | RHEL 8
Step 1 – Enable PHP Repository
By default, CentOS/RHEL repositories don’t contain the latest PHP 8 packages. In order to install PHP 8 on CentOS/RHEL, we need to enable EPEL and REMI yum repositories on the server. The EPEL and REMI yum repositories are both third-party repositories that contain a wider range of packages than the default CentOS/RHEL repositories.
To enable the EPEL repository, run the following command:
On CentOS/RHEL 8
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
On CentOS/RHEL 7
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
To install the Remi repository, run the following command:
On CentOS/RHEL 8
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
On CentOS/RHEL 7
sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Step 2 – Enable
remi-8.0 PHP Module
Before installing the PHP, we first need to enable the
remi-8.0. To do that, run:
On RHEL 8
sudo dnf module enable php:remi-8.0 -y
On CentOS 7
sudo yum -y install yum-utils sudo yum-config-manager --disable 'remi-php*' sudo yum-config-manager --enable remi-php80
Step 3 – Install PHP 8 on Apache and Nginx
After enabling the remi-8.0 PHP module, now let’s install PHP 8 on Apache and Nginx one by one.
Install PHP 8 on Apache
To install PHP 8 along with the commonly used extensions, run:
sudo dnf install php php-cli php-common
Once the installation is complete, restart the Apache webserver to load the PHP module by running:
sudo systemctl restart httpd
Install PHP 8 on Nginx
The command below installs PHP 8 along with commonly used PHP modules and PHP-FPM for Nginx.
sudo dnf install php php-cli php-common php-fpm
Once the installation is complete, restart the PHP-FPM service and Nginx web server by running the following command:
sudo service php8.1-fpm restart sudo service nginx restart
To install Nginx on CentOS, follow How to Install Nginx on CentOS 7: 4 Easy Steps.
Step 4 – Verify PHP 8 on CentOS/RHEL
To verify that PHP 8.0 is installed and functioning correctly on CentOS/RHEL, run the following command:
This command will display the PHP version information. If PHP 8.0 is installed correctly, you should see the PHP 8.0.x version number along with additional details.
Alternatively, create a PHP test file to verify that PHP is working with your web server. For example, create a file named info.php in your web server’s document root directory
/var/www/html/ with the following content:
Save the file and exit the text editor.
Open a web browser and enter the URL to access the info.php file. For example, if your server’s IP address is
22.214.171.124, enter the following URL in the browser:
This will display the PHP information page generated by the
If you see the PHP information page with details about PHP 8, it means PHP 8 is installed and functioning correctly on your CentOS/RHEL system.
After verifying PHP, it’s recommended to remove the
info.php file from your web server’s document root for security reasons.
Step 4 – Install PHP 8.0 Extensions in CentOS/RHEL
PHP extensions provide additional functionality to the PHP programming language. These extensions are libraries that extend the core functionality of PHP, allowing you to perform specific tasks or interact with various services, databases, protocols, or formats.
PHP extensions can provide functionality such as:
Database connectivity: Extensions like
pdo allow PHP to connect and interact with different database systems such as MySQL, PostgreSQL, SQLite, etc.
Image processing: The
gd extension enables PHP to manipulate and process images, including tasks like resizing, cropping, adding text or watermarks, and generating thumbnails.
Caching and optimization: Extensions like
apcu provide opcode caching and in-memory caching capabilities to improve PHP script performance.
JSON manipulation: The
json extension allows PHP to encode and decode JSON data, making it easier to work with JSON-based APIs.
XML processing: The
xml extension provides functionality to parse, create, and manipulate XML documents using PHP.
ZIP archive handling: The
zip extension enables PHP to create, extract, and manipulate ZIP archives programmatically.
These are just a few examples of the many PHP extensions available, each serving a specific purpose. You can install and enable the required extensions based on your project requirements to enhance the capabilities of your PHP applications.
For example, to install the PHP MySQL extension, run the following command:
sudo yum install php-mysqlnd
You can verify the installed extensions using the command:
To verify if a specific extension is installed or not, run:
php -m | grep extension-name
php -m | grep mysqlnd
This command confirms the installation of
You may also like:
- PHP for Beginners
- PHP for Beginners – Become a PHP Master – CMS Project
- Become a WordPress Developer: Unlocking Power With Code
In conclusion, this guide provided step-by-step instructions on How To Install PHP 8 on CentOS 7 | RHEL 8. By enabling the necessary repositories, such as EPEL and REMI, and enabling the
remi-8.0 PHP module, you were able to install PHP 8.0 on your CentOS 7 or RHEL 8 system. Additionally, we explored how to install PHP extensions to enhance the functionality of PHP, and verified the PHP installation by checking the PHP version and creating a PHP test file.
By following this guide, you now have PHP 8.0 installed on your CentOS 7 or RHEL 8 system, enabling you to take advantage of the latest features and improvements in PHP. You can further enhance PHP by installing additional extensions tailored to your specific needs.
Here are some additional resources that you may find helpful:
- PHP Documentation: https://www.php.net/manual/en/
- PHP Tutorial: https://www.phptutorial.net/
- PHP Stack Exchange: https://stackoverflow.com/questions/tagged/php
We hope you would find this tutorial on how to install PHP 8 on CentOS 7 | RHEL 8 useful.