8

I've set up my php5-fpm to bind to a unix domain socket within /var/run/php5-fpm.

/etc/php5/fpm/pool.d/www.conf

listen = /var/run/php5-fpm/$pool.sock

The problem is that it will not automatically create the php5-fpm directory. When I reboot the machine, the directory is gone.

How can I have it automatically created on boot? Or is there an other solution to this problem?

igorw
  • 181
  • 1
  • 3
  • That directory (`php5-fpm`) must exist first. – quanta Oct 18 '11 at 14:43
  • Hmm, just found a possible answer: http://serverfault.com/questions/74796/ Not the one I hoped for though. :-/ – igorw Oct 18 '11 at 14:45
  • 1
    @quanta so am I expected to create it by hand (or through an init script) every time I boot? seems ridiculous to me. I don't see why it needs to be that hard. – igorw Oct 18 '11 at 14:47
  • The init script should already be creating it for you. – Michael Hampton Dec 27 '13 at 09:18
  • 1
    If the directory is not being created, then you could always add a "mkdir" command to the init.d script that starts PHP-FPM. For my setup, I use /tmp to store them just because it's always there. – jaseeey Feb 05 '14 at 22:58
  • See my answer here: https://stackoverflow.com/questions/35367676/php-fpm-doesnt-create-sock-file/49930285#49930285 – Kirzilla Apr 19 '18 at 21:08

2 Answers2

3
  1. As you probably already discovered, /var/run is ephemeral by design. Check the FHS for more information on it and other directories.

  2. The /var/run/php5-fpm directory must exist prior to php-fpm trying to use. Neither php-fpm nor the init script seem to be creating it so you'll have to step in.

    The easiest option is to tweak your init script to create the directory in a way that is very specific to your environment. The downside is that this adds baggage that you'll have to carry on in your "sysadmin toolkit".

There are two other options that are more involved but would be permanent solutions for you and others:

  1. Submit a patch to php-fpm source code so that it checks for the existence of the directory defined in the .conf files. This will require knowledge of C and PHP's processes for patch submission.

  2. Submit a patch to your Linux distribution's init system so it does the same. This could be easier (compared to first option) and will probably require knowledge of shell script and again, your distro's processes for patch submission.

You can do the quick fix (change your init scripts) and move on, but a nice exercise would be to follow one of the permanent options so others can benefit. It's simple enough and might get you hooked on contributing to open source projects (if you don't already do it, pardon my ignorance).

Giovanni Tirloni
  • 5,693
  • 3
  • 24
  • 49
0

hey there you need to create the PHP directory inside the /run folder then restart PHP as root if you have php7.2 you need to write $ sudo /etc/init.d/php7.2-fpm restart

and everything should work as expected