The error message "nginx connect() to unix:/var/run/php" typically indicates that Nginx is trying to communicate with a FastCGI process manager (such as PHPFPM) via a Unix socket, but it's unable to establish the connection. This can happen for several reasons, including misconfigurations or issues with the PHPFPM service.
Here are some steps you can take to troubleshoot and resolve this issue:
1、Check PHPFPM Status:
Ensure that PHPFPM is running. You can check its status using the following command:
sudo systemctl status phpfpm
If it's not running, start it with:
sudo systemctl start phpfpm
2、Verify the Unix Socket Path:
Check your Nginx configuration file (usually located at/etc/nginx/nginx.conf
or within the/etc/nginx/sitesavailable/
directory) to ensure that the path to the PHPFPM Unix socket is correct. It should match the path configured in your PHPFPM pool configuration.
Example Nginx configuration snippet:
location ~ \.php$ { include snippets/fastcgiphp.conf; fastcgi_pass unix:/var/run/php/php7.4fpm.sock; # Adjust the path as necessary }
3、Check PHPFPM Pool Configuration:
Open the PHPFPM pool configuration file (e.g.,/etc/php/7.4/fpm/pool.d/www.conf
) and verify thelisten
directive. It should point to the same Unix socket path used in your Nginx configuration.
Example PHPFPM pool configuration snippet:
listen = /var/run/php/php7.4fpm.sock
4、Permissions:
Ensure that the permissions on the Unix socket file allow both Nginx and PHPFPM to access it. You can adjust the permissions using:
sudo chmod 660 /var/run/php/php7.4fpm.sock sudo chown wwwdata:wwwdata /var/run/php/php7.4fpm.sock
5、Restart Services:
After making any changes, restart both Nginx and PHPFPM services to apply the new configurations:
sudo systemctl restart nginx sudo systemctl restart phpfpm
6、Log Files:
Check the log files for more detailed error messages. Nginx logs are usually found in/var/log/nginx/
, and PHPFPM logs are typically in/var/log/php7.4fpm.log
or similar, depending on your PHP version.
By following these steps, you should be able to identify and resolve the issue preventing Nginx from connecting to the PHPFPM Unix socket.