Share your love
Easy Steps To Install PHP 7.4 on Centos 7

This tutorial intends to teach you to Install PHP 7.4 on Centos 7. At the current time, the latest version of PHP is PHP 8.2. But for some reason, if you plan to install PHP 7.4 on your Centos 7, you can follow this guide on the Orcacore website.
Important Note: It is recommended to always use the latest version, you can check this guide on Install PHP 8.2 on Centos 7.
Table of Contents
Steps To Install PHP 7.4 on Centos 7
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Centos 7.
Step 1 – Install Epel Repository on Centos 7
First, you need to update your local package index with the command below:
sudo yum update -y
Then, you need to install the Epel repository on Centos 7 with the command below:
sudo yum install epel-release -y
Step 2 – Install Remi Repository on Centos 7
PHP 7.4 is not available in the default Centos repository. So you can install PHP from the (Remi) repository that ships with PHP 7.4. To do this, run the following command:
sudo yum -y install yum-utils https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Run the system update again:
sudo yum update -y
Step 3 – Remove the PHP version Installed
Now you need to remove the PHP and PHP-FPM previous versions if you have them installed on your server. To do this, run the following command:
sudo yum remove php php-fpm -y
Then remove the rest of the package extensions with the command below:
sudo yum remove php* -y
Now disable the Remi repository for PHP with the following command:
sudo yum-config-manager --disable 'remi-php*'
Step 4 – Enable PHP 7.4 on Centos 7
To Install PHP 7.4 on Centos 7, you need to enable the Remi for PHP 7.4 on Centos 7 with the following command:
sudo yum-config-manager --enable remi-php74
Run the command below to see if the Remi repository for PHP 7.4 is enabled on your server:
sudo yum repolist
You should get the following output:
Output
remi-php74 | 3.0 kB 00:00
remi-php74/primary_db | 263 kB 00:00
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,761
extras/7/x86_64 CentOS-7 - Extras 515
remi-php74 Remi's PHP 7.4 RPM repository for Enterprise Linux 7 - x 459
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_ 5,263
updates/7/x86_64 CentOS-7 - Updates 5,053
repolist: 35,123
Step 5 – Install PHP 7.4 on Centos 7
At this point, you can Install PHP 7.4 on Centos 7 and some common extensions with the command below:
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,redis,memcache}
To install all the PHP extensions, you can use the following command:
sudo yum install php-xxx
Verify your PHP installation on Centos 7 by checking its version:
php --version

Step 6 – Configure PHP-FPM Service on Centos 7
By default on Centos 7, the PHP-FPM service is designed to be run by (Apache) user. If you are using Nginx you need to make configuration changes at (www.conf).
You can open the file with your favorite text editor, we use vi editor:
sudo vi /etc/php-fpm.d/www.conf
Find the user and group directives and change them to Nginx as shown below:
user = nginx
group = nginx
When you are done, save and close the file.
Reload the PHP-FPM service to apply the changes:
sudo systemctl restart php-fpm
The Nginx server block needs the following example below for Nginx to process the PHP files.
Below is an example for all server {} blocks that process PHP files that need the location ~ .php$ added.
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;
}
For more information, you can visit the PHP Documentation page.
Conclusion
At this point, you have learned to Install PHP 7.4 on Centos 7. Remember that PHP 7.4 reached its “End of Life” in November 2022 and it is recommended to use the LTS versions of PHP.
Hope you enjoy it. You may like these articles too:
Install PHP 8.2 on Rocky Linux 8