
Installing PHP 7.4 on CentOS 8 provides access to a widely used version for various web applications and development needs. Because CentOS 8 defaults to newer PHP versions, getting 7.4 requires enabling additional software repositories. Here’s a breakdown of the process to get it running smoothly on your system.
First, ensure your system is up-to-date. This is a crucial preliminary step to avoid conflicts and ensure you have the latest package information. Open your terminal and run the following command:
sudo dnf update -y
Next, you need to add the Extra Packages for Enterprise Linux (EPEL) repository, which provides common software packages. Run:
sudo dnf install epel-release -y
PHP packages, including different versions, are often available from the Remi repository. You’ll need to add this repository to your system as well:
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
Now that the necessary repositories are added, you need to enable the specific PHP module stream for version 7.4 from the Remi repository. This tells the system to prioritize packages from this stream when installing PHP. List the available PHP module streams first to confirm:
sudo dnf module list php
Look for the remi-7.4
stream. To enable it, execute:
sudo dnf module enable php:remi-7.4 -y
With the module enabled, you can now install PHP 7.4 itself. The basic installation includes the core PHP package.
sudo dnf install php -y
For most practical uses, you’ll also need various PHP extensions depending on your application requirements (e.g., for databases, image processing, etc.). Common extensions include php-cli
(for command-line execution), php-fpm
(for use with web servers like Nginx or Apache), php-mysqlnd
(for MySQL/MariaDB support), php-gd
(for image functions), and others. You can install multiple extensions in one command:
sudo dnf install php-cli php-fpm php-mysqlnd php-gd php-xml php-json php-mbstring -y
Install only the extensions you specifically need.
After the installation is complete, you can verify that PHP 7.4 is correctly installed by checking its version. Run the following command in your terminal:
php -v
The output should display PHP version 7.4 along with its build information.
If you plan to use PHP-FPM (which is common for web servers), you should start and enable the service so it launches automatically on boot:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
This comprehensive process ensures you have a functional PHP 7.4 environment set up on your CentOS 8 system, ready for deploying compatible applications or development work.
Source: https://kifarunix.com/install-php-7-4-on-centos-8/