To specify the PHP-FPM socket or port in Nginx configuration, you need to make changes to your Nginx virtual host configuration file. Here's how to do it:
Open the Nginx configuration file for your virtual host. This file is usually located at /etc/nginx/sites-available/<your_site_name>
.
Inside the server
block, locate the following line:
location ~ \.php$ {
Add the following lines after the location
block:
For PHP-FPM socket:
fastcgi_pass unix:/path/to/php-fpm.sock;
Replace /path/to/php-fpm.sock
with the actual path of your PHP-FPM socket file. For example, it could be /run/php/php7.4-fpm.sock
or /var/run/php/php7.4-fpm.sock
.
For PHP-FPM port:
fastcgi_pass 127.0.0.1:9000;
Replace 127.0.0.1:9000
with the actual IP address and port of your PHP-FPM server. By default, PHP-FPM listens on port 9000
.
Save the configuration file and exit the editor.
Test the Nginx configuration for syntax errors using the following command:
sudo nginx -t
If there are no errors, proceed to reload Nginx to apply the changes:
sudo systemctl reload nginx
If there are errors, double-check your configuration file for typos or incorrect paths.
Now, Nginx will forward PHP requests to PHP-FPM using the specified socket or port.