To configure Nginx to work with PHP-FPM, follow these steps:
Install Nginx and PHP-FPM on your server.
sudo apt update
sudo apt install nginx php-fpm
Configure PHP-FPM settings:
/etc/php/{PHP_VERSION}/fpm/pool.d/www.conf
.listen
directive and make sure it is set to the correct socket or IP address and port. By default, it may be set to listen = /run/php/php{PHP_VERSION}-fpm.sock
. If you are using a different setup, you may need to adjust this value.Configure Nginx to use PHP-FPM:
/etc/nginx/sites-available/{SITE_NAME}
.location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php{PHP_VERSION}-fpm.sock;
}
Replace {PHP_VERSION}
with the actual PHP version you are using.Test the configuration and restart the services:
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl restart php{PHP_VERSION}-fpm
Again, replace {PHP_VERSION}
with the actual PHP version you are using.Now Nginx should be configured to work with PHP-FPM. You can place your PHP files in the appropriate directory defined in the Nginx configuration file and access them via your domain or IP address.