When running multiple php-fpm pools or configuring custom ports its crucial to know which ports are already in use to avoid conflicts.

In this post Ill show you how to identify the ports used by php-fpm on your system.

Why This Matters
  • Prevent port conflicts when running multiple php-fpm instances
  • Useful when managing multiple PHP versions eg PHP 8.1, 8.2, 8.3, 8.4 sidebyside
  • Helps with debugging connection issues between nginx and php-fpm
     

Check Active Listening Ports with ss or netstat

Doing it with ss:

sudo ss -ltnp | grep php-fpm

The result could look like this:

sommer@web01-ubuntu-4gb-nbg1-1:/etc/php$ sudo ss -ltnp | grep php-fpm
LISTEN 0      4096       127.0.0.1:8009       0.0.0.0:*    users:(("php-fpm8.3",pid=11085,fd=11),("php-fpm8.3",pid=11084,fd=11),("php-fpm8.3",pid=11081,fd=9))                                
LISTEN 0      4096       127.0.0.1:8008       0.0.0.0:*    users:(("php-fpm8.4",pid=11414,fd=12),("php-fpm8.4",pid=11413,fd=12),("php-fpm8.4",pid=11411,fd=8))                                
LISTEN 0      511        127.0.0.1:8007       0.0.0.0:*    users:(("php-fpm8.1",pid=7151,fd=12),("php-fpm8.1",pid=7150,fd=12),("php-fpm8.1",pid=7145,fd=10))                                  
LISTEN 0      4096       127.0.0.1:8006       0.0.0.0:*    users:(("php-fpm8.4",pid=24199,fd=12),("php-fpm8.4",pid=11418,fd=12),("php-fpm8.4",pid=11417,fd=12),("php-fpm8.4",pid=11411,fd=10))
LISTEN 0      511        127.0.0.1:8005       0.0.0.0:*    users:(("php-fpm8.1",pid=7149,fd=12),("php-fpm8.1",pid=7148,fd=12),("php-fpm8.1",pid=7145,fd=9))                                   
LISTEN 0      4096       127.0.0.1:8004       0.0.0.0:*    users:(("php-fpm8.2",pid=11399,fd=10),("php-fpm8.2",pid=11398,fd=10),("php-fpm8.2",pid=11397,fd=8))                                
LISTEN 0      511        127.0.0.1:8003       0.0.0.0:*    users:(("php-fpm8.1",pid=7147,fd=12),("php-fpm8.1",pid=7146,fd=12),("php-fpm8.1",pid=7145,fd=8))                                   
LISTEN 0      4096       127.0.0.1:8002       0.0.0.0:*    users:(("php-fpm8.4",pid=45905,fd=12),("php-fpm8.4",pid=11416,fd=12),("php-fpm8.4",pid=11415,fd=12),("php-fpm8.4",pid=11411,fd=9)) 
LISTEN 0      4096       127.0.0.1:8001       0.0.0.0:*    users:(("php-fpm8.3",pid=11083,fd=11),("php-fpm8.3",pid=11082,fd=11),("php-fpm8.3",pid=11081,fd=8))

Another way we could do it, is with netstat which also does the job well:

sudo netstat -ltnp | grep php-fpm

Result:

sommer@web01-ubuntu-4gb-nbg1-1:/etc/php$ sudo netstat -ltnp | grep php-fpm
tcp        0      0 127.0.0.1:8009          0.0.0.0:*               LISTEN      11081/php-fpm: mast 
tcp        0      0 127.0.0.1:8008          0.0.0.0:*               LISTEN      11411/php-fpm: mast 
tcp        0      0 127.0.0.1:8007          0.0.0.0:*               LISTEN      7145/php-fpm: maste 
tcp        0      0 127.0.0.1:8006          0.0.0.0:*               LISTEN      11411/php-fpm: mast 
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      7145/php-fpm: maste 
tcp        0      0 127.0.0.1:8004          0.0.0.0:*               LISTEN      11397/php-fpm: mast 
tcp        0      0 127.0.0.1:8003          0.0.0.0:*               LISTEN      7145/php-fpm: maste 
tcp        0      0 127.0.0.1:8002          0.0.0.0:*               LISTEN      11411/php-fpm: mast 
tcp        0      0 127.0.0.1:8001          0.0.0.0:*               LISTEN      11081/php-fpm: mast

By combining system tools like ss, netstat with php-fpm config inspection you can easily find which ports are already used. Always doublecheck your pool settings before adding a new one to avoid accidental conflicts.