How does PHP-fpm work in conjunction with nginx or lighttpd?

PHP-fpm works in conjunction with nginx or lighttpd by acting as a FastCGI process manager for PHP. This allows the web server to communicate with PHP scripts efficiently, improving performance and scalability. To set up PHP-fpm with nginx or lighttpd, you need to configure the web server to pass PHP requests to the PHP-fpm process manager.

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