PHP-FPM
php-fpm.sock
troubleshooting
configuration
web server setup

How to find my php-fpm.sock?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The location of php-fpm.sock is not universal because it depends on your PHP-FPM pool configuration and Linux distribution. The reliable way to find it is to inspect the listen directive for the pool your web server uses, then verify that the socket file exists and that the web server can access it.

Understand What You Are Looking For

PHP-FPM can listen in two different ways:

  • a Unix socket such as /run/php/php8.2-fpm.sock
  • a TCP address such as 127.0.0.1:9000

If your pool is configured for TCP, there is no .sock file to find. That is the first thing to confirm before you go searching the filesystem.

The setting that decides this is named listen and usually lives in a pool file such as www.conf.

Search The Configuration First

Start by grepping the PHP-FPM configuration directories for listen lines.

bash
grep -R "^listen\s*=" /etc/php /etc/php-fpm* 2>/dev/null

Common results look like this:

text
/etc/php/8.2/fpm/pool.d/www.conf:listen = /run/php/php8.2-fpm.sock

or:

text
/etc/php-fpm.d/www.conf:listen = /run/php-fpm/www.sock

That line is the authoritative source. Do not guess the path from a blog post or from another server.

Common Pool File Locations

Different distributions place the files in different directories:

  • Debian and Ubuntu often use /etc/php/<version>/fpm/pool.d/
  • RHEL, CentOS, AlmaLinux, and Rocky often use /etc/php-fpm.d/
  • some custom builds keep everything under /usr/local/etc/

The main service file may include many pool files, so check the pool that matches the site you are configuring.

Verify The Socket Exists

After you find the configured path, check whether the file is actually present.

bash
ls -l /run/php/php8.2-fpm.sock

If the socket does not exist, PHP-FPM may not be running or the service may have failed to start. Inspect service status and logs:

bash
systemctl status php8.2-fpm
journalctl -u php8.2-fpm --no-pager -n 50

Replace the service name with the version installed on your system.

Use The Running Configuration As A Cross-Check

Some PHP-FPM builds can print the parsed configuration, which is useful when includes and overrides make the file layout confusing.

bash
php-fpm8.2 -tt 2>&1 | grep listen

On other systems the binary might be php-fpm or php-fpm8.1. The goal is the same: inspect the effective listen settings as PHP-FPM sees them.

Match Nginx Or Apache To The Same Endpoint

Once you know the actual socket path, make sure the web server uses the same value.

For Nginx, the important directive is often:

nginx
1location ~ \.php$ {
2    include fastcgi_params;
3    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
4    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
5}

If PHP-FPM listens on TCP instead, fastcgi_pass should point to the TCP address instead of a Unix socket.

For Apache with proxy_fcgi, the equivalent configuration also needs to reference the same backend endpoint. A mismatch between web server config and PHP-FPM pool config is one of the most common causes of 502 Bad Gateway or No such file or directory errors.

Permissions Matter Too

Finding the socket is only half the job. The web server user must also be allowed to use it.

Check the pool settings named listen.owner, listen.group, and listen.mode. If Nginx runs as www-data but the socket is owned by another user and has restrictive permissions, the path may exist but still fail at runtime.

Common Pitfalls

The first pitfall is assuming there must be a .sock file. If the pool listens on 127.0.0.1:9000, no socket file will exist.

Another mistake is editing the wrong pool file. Many systems have multiple pools, and the site may not use www.conf at all.

People also search only the filesystem and not the configuration. Since PHP-FPM recreates sockets at startup, the configured listen path is more trustworthy than a stray file left behind from an older setup.

Finally, do not stop after finding the path. A correct socket location is still useless if PHP-FPM is down or the permissions are wrong.

Summary

  • Find the listen directive in the active PHP-FPM pool configuration.
  • Confirm whether the pool uses a Unix socket or a TCP port.
  • Verify that the configured socket file actually exists while PHP-FPM is running.
  • Make sure Nginx or Apache points to the same backend endpoint.
  • Check socket ownership and mode if the path exists but requests still fail.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.