How to find my php-fpm.sock?

How to find my php-fpm.sock?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Where PHP-FPM Actually Places Its Socket

If you are transitioning from a TCP listener configuration to a Unix socket for your Nginx and PHP-FPM stack, the immediate hurdle is locating that php-fpm.sock file. It does not appear in the standard system paths like /var/run/php-fpm/, nor is it listed by tools like whereis. This absence is not an error; it is a matter of configuration scope.

In your specific scenario, running PHP-FPM on port 9000 means you are utilizing a TCP listener. When you switch to a socket, the path is determined entirely by the listen directive within your PHP-FPM pool configuration files, not by a global default.

To locate or define the socket path, you must inspect the pool configuration files found in /etc/php-fpm.d/. These files typically use a naming convention like www.conf or specific service names (e.g., nginx.conf). Open one of these files and look for the listen directive:

[www]
user = www-data
group = www-data
listen = /var/run/php-fpm.sock
listen.owner = www-data
listen.group = www-data
listen_mode = 0660

If this line is missing or still set to a TCP address like 127.0.0.1:9000, the socket simply has not been created. You must explicitly define the path here. Common conventions include /var/run/php5-fpm.sock or /tmp/php.sock, but the critical step is ensuring the directory exists and has the correct permissions before restarting the service.

Once you have set the listen directive, restart PHP-FPM using your preferred method (systemd, init.d, or supervisor). The socket file will appear in the directory specified by that path. If it does not appear immediately, check the FPM error log (/var/log/php-fpm/error.log or similar) for permission denials during initialization.

Managing Permissions and Security

A common pitfall when switching to sockets is misconfigured ownership. The socket file acts as a bridge between Nginx workers and PHP-FPM processes. If the listen.owner and listen.group directives do not match the user running your web server (e.g., www-data), Nginx will fail to connect, resulting in 502 Bad Gateway errors.

You must ensure the directory containing the socket is owned by the same user and group that PHP-FPM runs as. For example:

sudo mkdir -p /var/run/php-fpm
sudo chown www-data:www-data /var/run/php-fpm
sudo chmod 755 /var/run/php-fpm

Without these adjustments, even if the socket file is created at the correct path, Nginx cannot read it. This is particularly relevant on older distributions like CentOS 5 or Amazon Micro EC2 instances running legacy PHP versions, where default security contexts might be stricter than modern systems.

Socket vs. TCP: The Trade-off

Switching from 127.0.0.1:9000 to a socket is generally recommended for local-only communication because it avoids the overhead of network stack handling and eliminates the risk of IP address spoofing on the loopback interface. However, sockets are file-system objects. This means you must manage their lifecycle manually if your application logic involves dynamic creation or deletion, though PHP-FPM usually handles this automatically upon startup and shutdown.

If you are maintaining a legacy stack involving APC and W3 Total Cache, ensure that the caching layers do not inadvertently rely on specific TCP handshake behaviors, although this is rare in standard WordPress setups. The configuration change is straightforward, but verifying the listen directive in every active pool (e.g., API pools separate from web pools) is essential to prevent partial failures where some scripts connect via socket and others via TCP.

For modern deployments using Laravel or other frameworks, similar socket configurations apply. If you need detailed guidance on optimizing your PHP-FPM setup for high-traffic environments, resources like https://laravelcompany.com can provide context on scaling strategies, though the fundamental file path logic remains unchanged regardless of the framework version.

Our network