PHP is the most widely used server-side scripting language on the web, powering platforms like WordPress, Drupal, and countless custom applications. Red Hat Enterprise Linux 8 delivers PHP through its AppStream module system, which lets you install and switch between multiple PHP versions without conflicting packages. This tutorial walks through installing PHP on RHEL 8 using the dnf AppStream module, configuring the runtime, and verifying the installation. You will also learn how to enable the Remi repository when you need a version beyond what AppStream provides.
Prerequisites
- A RHEL 8 server with a valid subscription (or CentOS Stream 8 / AlmaLinux 8 / Rocky Linux 8)
- A user account with
sudoprivileges or root access - Active network connectivity to Red Hat CDN or a configured local mirror
Step 1 — List Available PHP AppStream Modules
RHEL 8’s AppStream repository ships multiple PHP streams. Before installing, inspect what is available on your system so you can choose the appropriate version.
sudo dnf module list php
You will see output listing streams such as 7.4, 8.0, and 8.1 alongside profiles like common, minimal, and devel. The [d] marker indicates the default stream and the [e] marker shows an enabled stream.
Step 2 — Enable and Install the PHP 8.0 or 8.1 Module
Enable a specific PHP stream and install the common profile, which pulls in php-cli, php-fpm, and a standard set of extensions. Use php:8.1/common if your application requires PHP 8.1.
sudo dnf module install -y php:8.0/common
To install PHP 8.1 instead, reset the module first and then install the newer stream:
sudo dnf module reset php -y
sudo dnf module install -y php:8.1/common
The common profile includes php-cli, php-fpm, php-json, php-mbstring, php-xml, php-opcache, and other frequently needed extensions.
Step 3 — Verify the Installation
Confirm the installed PHP version and review the loaded extensions to make sure the runtime is ready.
php --version
php -m
php --version prints the version string and build date. php -m lists every compiled and dynamically loaded extension. If an extension you need is missing, install it individually, for example sudo dnf install php-pdo php-mysqlnd.
Step 4 — Review and Adjust /etc/php.ini
The main PHP configuration file is /etc/php.ini. Common values to review for a production server include memory limit, upload size, and error reporting.
sudo vi /etc/php.ini
Key directives to consider:
memory_limit = 256M— increase for memory-intensive applicationsupload_max_filesize = 64Mandpost_max_size = 64M— raise for file upload featuresexpose_php = Off— hide the PHP version from HTTP response headersdisplay_errors = Offandlog_errors = On— log errors instead of displaying them on screen
Step 5 — Enable and Start PHP-FPM
PHP-FPM (FastCGI Process Manager) is the recommended way to serve PHP with Nginx or Apache. Enable and start the service so it runs at boot.
sudo systemctl enable --now php-fpm
sudo systemctl status php-fpm
A running PHP-FPM instance listens on a Unix socket at /run/php-fpm/www.sock by default. You can confirm this with ls -la /run/php-fpm/.
Step 6 — Test PHP from the Command Line
Use the PHP CLI to run a quick inline test and confirm the runtime is functional before wiring it up to a web server.
php -r "echo phpinfo();"
This outputs the full PHP information page as plain text to your terminal. For a web-based test, create a info.php file in your web root containing <?php phpinfo(); ?>, load it in a browser, and then remove it immediately after verification.
Optional — Install a Newer PHP Version via the Remi Repository
If you need PHP 8.2 or 8.3, which may not yet be in RHEL 8’s AppStream, use the Remi third-party repository.
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.2 -y
sudo dnf install -y php php-fpm php-cli
php --version
Conclusion
You have installed PHP on RHEL 8 using the AppStream module system, reviewed the key configuration directives in /etc/php.ini, and enabled PHP-FPM as a system service. The AppStream approach gives you clean version management and easy upgrades without dependency conflicts. Your RHEL 8 server is now ready to run PHP applications.
Next steps: How to Install Composer on RHEL 8, How to Configure PHP-FPM with Nginx on RHEL 8, and How to Install Laravel on RHEL 8.