Where is php7.0-fpm.sock located
When configuring Nginx for a Drupal site, many developers default to fastcgi_pass 127.0.0.1:9000. While this TCP approach works, using a Unix socket is often preferred in production environments because it avoids the overhead of establishing a network stack and can offer better performance under load. However, switching configurations often leads to a common stumbling block: the standard path /var/run/php/php7.0-fpm.sock simply does not exist on the system.
If you are working with CentOS or RHEL distributions, specifically those using PHP 7.0-FPM, you will likely encounter this discrepancy. In many default installations for these distros, the socket is not created at /var/run/php/. Instead, the process ID file often resides at /var/run/php-fpm/php-fpm.pid, which suggests a different directory structure is being used for runtime files.
The location of the socket is almost always determined by the listen directive inside your PHP-FPM pool configuration file, not by a system-wide default that you might expect. On CentOS systems, this configuration is typically located in /etc/php-fpm.d/. You can inspect the active pools to find the correct path. Look for files named www.conf, pool-www.conf, or similar within that directory.
To verify the exact location without guessing, run the following command:
grep -r "^listen" /etc/php-fpm.d/
This output will reveal the full filesystem path where the socket is actually being created. For example, you might see listen = /var/run/php-fpm/www.sock or listen = /tmp/php.sock. The directory containing the .pid file you found (/var/run/php-fpm/) is a strong hint that your sockets are likely residing in that same directory rather than under /var/run/php/.
Once you identify the correct path, update your Nginx configuration accordingly:
fastcgi_pass unix:/var/run/php-fpm/www.sock;
# OR whatever path your grep command revealed
A critical pitfall when switching from TCP to Unix sockets involves file permissions. Since PHP-FPM runs as a specific user (often www-data or nobody), the socket must be readable by the Nginx worker process. If you receive a Permission denied error after changing the fastcgi_pass directive, check the ownership and mode of the socket file:
ls -l /var/run/php-fpm/www.sock
If the permissions are too restrictive, you may need to adjust them or ensure the Nginx user matches the PHP-FPM user. Common issues include the socket being owned by root while Nginx runs as nginx or www-data, or having a mode of 0755 when it needs to be world-readable for the specific user context.
Another consideration is the directory lifecycle. Unlike TCP listeners which bind to ports that persist until killed, Unix sockets are tied directly to the parent directory. If you restart PHP-FPM and the /var/run/php-fpm/ directory does not exist or has been removed, the socket will fail to create. Ensure this directory exists and has appropriate permissions before starting the service:
mkdir -p /var/run/php-fpm
chmod 755 /var/run/php-fpm
chown www-data:www-data /var/run/php-fpm
systemctl restart php-fpm
In some modern PHP installations, the socket path might be configured via listen.owner and listen.group directives to enforce strict security models. If you are migrating from a shared hosting environment or a Docker container where paths are mounted differently, always verify the runtime configuration inside the specific environment rather than assuming a host-path mapping.
If your setup involves multiple PHP versions (e.g., PHP 7.0 alongside PHP 8.x), ensure you are looking in the pool files corresponding to the version running your Drupal instance. Mixing up configuration directives between different FPM pools is a frequent source of errors that manifests as connection timeouts or "upstream prematurely closed connection" logs in Nginx.
For developers managing complex stacks, understanding where these sockets live prevents fragile configurations that break during routine updates or server reboots. If you need further guidance on optimizing your PHP-FPM and Nginx integration for high-traffic sites, resources like https://laravelcompany.com offer deep dives into performance tuning strategies that complement this foundational networking knowledge.