Score:0

How is php-fpm socket folder ({/var,}/run/php-fpm) created on Linux?

ru flag

I am setting up multiple php versions on CentOS7 (native and from remi repos). As installed, the native php-fpm ( is setup on a unix socket, while the (remi) php74-php-fpm would listen on a TCP socket. I changed that by setting:

  listen = /run/php-fpm/php74.sock
  ...
  listen.owner = nobody
  listen.group = nobody
  listen.mode  = 0666

which is OK as long as both services are running. However if I stop both services, then start ONLY php74-php-fpm the socket folder (/run/php-fpm) is missing and the service fails. I looked in the obvious place (/usr/lib/tmpfiles.d/*) for the folder creation, but it's not mentioned there. I also inserted (via systemctl edit) the lines:

[Service]
RuntimeDirectory=php-fpm
RuntimeDirectoryMode=0755

in php74-php-fpm.service, (the lines come from the native php-fpm) speculating that thhey would make systemd create the folder at startup, but it's not happening.

Hence the question - How do I force the folder creation when starting php74-php-fpm? I would rather not dick around with shell hacks and somesuch as I believe the native php-fpm is using a somewhat "standard" approach, which I would prefer.

TIA & cheers.

us flag
Do you have an explicit requirement that the sockets are in `/run/php-fpm` directory? I would just use `/run/php7.4.sock` as the socket entry. The creation of `php-fpm` directory in native package is likely an extra adjustment from the package maintainers, and would need to be ported to the remi packages separately.
Alien Life Form avatar
ru flag
@TeroKilkanen read the answer I posted below to see where I messed up.
Score:0
ru flag

So it turns out that adding:

[Service]
RuntimeDirectory=php-fpm
RuntimeDirectoryMode=0755

does indeed force the creation of the /var/run/php-fpm folder, but this is needed only on Centos7.

And of course I messed up. I was changing a mix of CentOS8 machines (where the problem does not exist - bottom section explains why) and CentOS7 machines, ran systemctl edit on the CentOS7 machinines, then checked for the existence of /run/php-fpm on a CentOS8 machine (too many terminals).

What happens is, on CentOS8 php-fpm is the default for apache, and the remi www.conf, as well as the supplied apache config php74-php-fpm.conf reflect that, setting the socket folder to /var/opt/remi/php74/run/php-fpm/ (a non volatile folder).

On Centos7, however, mod_php is the default, and remi apache configuration file makes no php-fpm provision (one has to set it up in the site config files). Following the native php-fpm config, I set the socket folder to /run/php-fpm, which is volatile and managed by systemd - making it necessary to change the php74-php-fpm service definition in order to create the folder at startup.

So it appears that there are multiple methods of managing volatile directories, which I think is confusing and error prone, as it appears people are using both with no discernible rationale. But what do I know.

Remi Collet avatar
jp flag
Duplicate of https://stackoverflow.com/questions/76278759/how-is-php-fpm-socket-folder-var-run-php-fpm-created-on-linux/76279335
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.