connect() to unix:/run/php/php7.4-fpm.sock failed

The first step is to check the php version installed on your machine:

php -version

If the output is PHP 8, you need to follow the following steps:

Find the exact php sock you have on your Ubuntu machine, you can refer the following blog for doing the same: Find the php sock installed on Ubuntu

Let’s say the sock is php8.1, you will have to use that version in the nginx file for your site.

Go to your nginx site which is throwing the connect() to unix:/run/php/php7.4-fpm.sock failed error:

sudo nano /etc/nginx/sites-enabled/<yoursite>

Find the following section in that file:

   location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

and replace it with:

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

Restart nginx service following How to restart nginx service on Ubuntu and your issue will be fixed.