Install PHP7.4 on Cent OS

Jan 12, 2022    Janaki Mahapatra, Installation

# Install Nginx:
sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx

# Install PHP
sudo yum install
yum --disablerepo="*" --enablerepo="remi-safe" list php[7-9][0-9].x86_64
sudo yum-config-manager --enable remi-php74
sudo yum install php php-cli php-common php-fpm php-zip php-gd php-mcrypt php-curl php-json php-mbstring php-mysqlnd php-xml php-xmlrpc php-opcache php-pdo php-mysqli -y

# test php by
php -v

# Configure php for nginx via php-fpm
sudo vim /etc/php-fpm.d/www.conf
# Find user and group and change them from apache to nginx as below
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

# Change the line containing the listen directive to the following:
listen = /var/run/php-fpm/php-fpm.sock;

#  Locate the listen.owner, and listen.mode directives and change them as below
listen.owner = nginx = nginx
listen.mode = 0660

# once you save the changes, restart the php-fpm service
sudo systemctl start php-fpm

Create a new nginx virtual site like below:

# run this command
sudo vim /etc/nginx/conf.d/default.conf

# now add this
server {
    listen       80;
    server_name  server_domain_or_IP;

    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

# save the changes and restart the nginx service as
sudo systemctl restart nginx