Find the php sock installed on Ubuntu

On Ubuntu, you can run the following command in your terminal to locate the PHP sock:

sudo find / -name 'php*sock'

The output will be like this:

/etc/alternatives/php-fpm.sock
/run/php/php-fpm.sock
/run/php/php8.1-fpm.sock

This command will look for any files with the name “php” followed by “sock” throughout the whole file system, beginning at the root directory. Any files that match this pattern will have their complete path returned.

The location of the sock file can also be found by looking in the PHP configuration file.

sudo nano /etc/php/8.1/fpm/pool.d/www.conf

Replace the version in the above command with the PHP version installed on your machine. The output of the above command will have the text containing:

; ‘/path/to/unix/socket’ – to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php8.1-fpm.sock

The listen = line, which contains the path of the sock file, will be searched for when this program opens the PHP-FPM configuration file (php-fpm).

Alternatively, run the following command on your machine to get the php sock installed on your Ubuntu machine:

php -version

The output will be like this:

PHP 8.1.2 (cli) (built: Jul 21 2022 12:10:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Next, run the following command:

ls /run/php/

The output will be like this:

php-fpm.sock  php8.1-fpm.pid  php8.1-fpm.sock

In the above example, php8.1 is the sock installed on the machine.

Alternatively, you can also run the following command:

sudo php -i | grep -i 'php sock'

The PHP sock file’s location and other details about your PHP installation are displayed by this command.

You should be able to locate the PHP sock file on your Ubuntu machine with the above commands.