PHP, a renowned open-source programming language, is pivotal for web development and seamlessly integrates with CentOS Stream. It is essential to understand its core benefits and features to install PHP 8.3, 8.2, 8.1, 8.0, or 7.4 on CentOS Stream 9 or its older enterprise-base release of CentOS Stream 8.
Key Advantages of PHP:
- Server-Side Scripting: PHP’s server-side execution allows dynamic web page generation, enhancing security and user experience.
- Cross-Platform Flexibility: PHP’s compatibility across Windows, Mac, and Linux platforms ensures its adaptability in diverse web development scenarios.
- Robust Community Support: A vast community of PHP developers ensures continuous improvements, support, and resources.
- Database Integration: PHP’s innate support for databases like MySQL, PostgreSQL, and Oracle simplifies data-driven web application development.
- Interoperability: Integration capabilities with technologies such as JavaScript and AJAX enable the creation of interactive web applications.
- Comprehensive Libraries: PHP’s extensive libraries and frameworks, including Laravel and CodeIgniter, expedite and simplify development.
- Cost-Effective: Being open-source, PHP is a budget-friendly choice, especially for startups and individual developers.
- High Performance: With optimizations and features like JIT compilation in PHP 7 and later, PHP ensures swift and efficient web application performance.
In essence, PHP’s versatility, combined with its robust features, makes it an invaluable asset for web developers. Integrating PHP versions 8.3, 8.2, 8.1, 8.0, or 7.4 is now streamlined with the Remi PHP repository for those using CentOS Stream. Our subsequent guide will provide a detailed walkthrough on adeptly installing these PHP versions on CentOS Stream.
For users seeking to install PHP 7.4, PHP 7.4.33 was the final official update for PHP 7.4. If security is your concern, it’s imperative to shift to a version that’s still supported.
For those seeking additional details on PHP 8.x:
- PHP 8.0, now on security-only support, will receive updates until November 2023.
- PHP 8.1 is actively supported, and its maintenance is planned until November 2023, with security updates lasting until 2024.
- PHP 8.2 is scheduled for active support until December 2024, and its security updates will run into 2025.
Table of Contents
Update CentOS Stream 9 or 8 Before PHP Installation
Before installing any new software, updating the system is always a good idea. To do this, open a terminal and run the following commands:
sudo dnf upgrade --refresh
Import Remi PHP RPM Repo on CentOS Stream 9 or 8
To access the Remi PHP repository, it is necessary first to install the EPEL (Extra Packages for Enterprise Linux) repository. EPEL is a valuable resource, particularly for new users of distributions like CentOS Stream, which is built on RHEL and provides a vast array of commonly used software packages for Enterprise Linux.
Make sure to import the appropriate repository for your version of CentOS Stream.
Import Remi PHP Repository for CentOS 9 Stream
While this is optional for EL9, it is recommended to enable the CRB.
sudo dnf config-manager --set-enabled crb
With the CRB enabled, execute the following command to install both versions of EPEL for EL9.
sudo dnf install \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm
Use the command below to import the EL 9 Remi repository.
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
Import Remi PHP Repository for CentOS 8 Stream
To start, use the command below to enable EPEL for EL8.
sudo dnf install \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-8.noarch.rpm
Now, use this command to import the Remi EL 8 repository that contains PHP.
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
Enable PHP Remi Repository on CentOS Stream 9 or 8
To ensure you can view all versions of the REMI PHP repository, list the PHP modules first and then adjust your selection as needed once it is confirmed.
dnf module list php
If prompted, enter (Y) to import the GPG key for Remi’s repository to proceed.
After that, activate the version of PHP you want to install below.
Currently, all the versions are available, but as a recommendation, PHP 8.1 to 8.2 should be considered for the best stability, with PHP 8.0 more as a last resort. Remember, PHP 7.4 should not ideally be used as it reaches EOL.
sudo dnf module enable php:remi-8.3 -y
sudo dnf module enable php:remi-8.2 -y
sudo dnf module enable php:remi-8.1 -y
sudo dnf module enable php:remi-8.0 -y
sudo dnf module enable php:remi-7.4 -y
Install PHP 8.3, 8.2, 8.1, 8.0 or 7.4 on CentOS Stream
Now that the Remi PHP repository is enabled, you can install the PHP. Below are some options to choose between Apache and Nginx, but you can customize these further if you know what extensions to install for your CMS or software development.
Apache (httpd) PHP:
sudo dnf install php php-cli -y
Nginx PHP:
sudo dnf install php-fpm php-cli -y
After the installation, execute the following command to verify that PHP has been installed correctly.
php -v
Optionally, run the command below to obtain the most frequently used extensions for your selected version of PHP. Be sure to remove any extensions you know are not needed.
sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache
You can execute the command below at any time to view the currently loaded modules.
php -m
It is recommended to regularly monitor and remove any unnecessary modules, as many installed modules can negatively impact system performance.
If you want to install the development branch, use the command below:
sudo dnf install php-devel
To add additional development tools, such as debugging tools, use the command given below.
sudo dnf install php-xdebug php-pcov
It’s worth noting that installing this version will introduce multiple dependencies, and it’s not suggested unless you have a specific need for it in your PHP development or any specific requirement.
Set Up Nginx user for PHP-FPM on CentOS Stream
When installing PHP-FPM on distributions like Debian/Ubuntu, the “www-data” user is often used. However, this is not the default for installations on the RHEL family. By default, the PHP-FPM service is configured to run under the “Apache” user, which is unsuitable for Nginx use. Therefore, adjustments need to be made.
First, open the configuration file (www.conf) with the following command.
sudo nano /etc/php-fpm.d/www.conf
Then, substitute the (Apache) user and group with the (Nginx) user and group.
Example from:
Example to:

To save, press (CTRL+O), then exit (CTRL+X).
Now, you can restart your PHP-FPM service.
sudo systemctl restart php-fpm
Example Nginx PHP-FPM Server Block Code on CentOS Stream
For Nginx to process PHP files, the server block needs a specific configuration, as demonstrated in the example below. This example applies to all server{} blocks that handle PHP files and necessitates the inclusion of “location ~ \.php$.”
Example ONLY:
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
To confirm that the changes to the code above did not cause any errors, execute the following command to test Nginx:
sudo nginx -t
Example output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
To finish the PHP-FPM setup, the Nginx service needs to be restarted.
sudo systemctl restart nginx
Conclusion
This guide covered installing PHP on CentOS Stream by activating the Remi PHP repository, making the chosen version of PHP the default, installing popular extensions, and configuring the Nginx server block to handle PHP files. It’s crucial to monitor dependencies and eliminate unnecessary modules. Also, it’s essential to test Nginx for errors before restarting the service in the future, particularly in a live environment.