6

I've created a directory to store socket files for PHP 5 FPM: sudo mkdir /var/run/php-fpm. It is owned by root:root as well as core PHP FPM process.

When PHP FPM is starting, it creates socket files for each pool inside of this directory and nginx uses them to communicate.

However, when I reboot my machine (sudo reboot) this directory is gone after reboot and PHP FPM can't start, cause it can't create socket files inside of a missing directory.

What can be the problem? How do I debug it?

I'm using latest Ubuntu Server 14.04.

2 Answers 2

5

Current version of Ubuntu is using so-called up-start configs to run services. More info about this can be found here.

All up-start scripts are located in the /etc/init directory. Do not confuse it with old init scripts in /etc/init.d directory.

As @Rhim stated in his answer, /var/run is a temporary mounted filesystem, that is re-created after each reboot, so changes are not persisted in it. So in order to have a custom directory for socket files you will have to create it every time. The best place to add such functionality is an upstart config for PHP FPM located in: /etc/init/php5-fpm.conf.

Here's the modified version of this config:

# php5-fpm - The PHP FastCGI Process Manager

description "The PHP FastCGI Process Manager"
author "Ondřej Surý <[email protected]>"

start on runlevel [2345]
stop on runlevel [016]

# Precise upstart does not support reload signal, and thus rejects the
# job. We'd rather start the daemon, instead of forcing users to
# reboot https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1272788
#
# reload signal USR2

pre-start script
    mkdir -p /var/run/php-fpm
    /usr/lib/php5/php5-fpm-checkconf
end script

respawn
exec /usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.conf

pre-start stanza was already used to check PHP FPM configuration file so I've converted it to a script section and added my own command for creating the direcotry for socket files before calling the checkconf.

With this script it should work fine. In order to control state of the service use the service command like this: service php5-fpm start, service php5-fpm restart etc.

I hope it will help someone. Cheers!

2
  • isn't /etc/init/php5-fpm.conf file overwrited after php-fpm package is updated?
    – sepehr
    Feb 21, 2015 at 19:48
  • A valid concern. However, I'm not sure about this. I'm running this setup for at least half a year with automatic updates. No problems so far, no conflicts. etc. Feb 21, 2015 at 19:53
1

I think that in Ubuntu also!

cat /etc/redhat-release 
Fedora release 20 (Heisenbug)

df -h /run
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           3.9G  904K  3.9G   1% /run

ls -la /var | grep run 
lrwxrwxrwx.   1 root root      6 Dec 28  2013 run -> ../run

This directory is mounted as tmpfs.

Add to a startup script, create a directory or change the directory for pid files.
But I am surprised that it is not created automatically after reboot.

6
  • Oh, I see. Is it OK to alter the /etc/init.d/php5-fpm script or is it better to create my own startup script then? Jul 26, 2014 at 11:01
  • Show section start() in file etc/init.d/php5-fpm
    – Rhim
    Jul 26, 2014 at 11:19
  • I think you need to add dir=$(dirname ${pidfile}) [ -d $dir ] || mkdir $dir in the beginning of the function start(). Variable pidfile must be defined /var/run/php-fpm/php-fpm.pid
    – Rhim
    Jul 26, 2014 at 11:32
  • I'm sorry for the delay. Here's the requested piece of script: gist.github.com/slavafomin/cef2d5b0f6c6b5a011b2 Aug 3, 2014 at 10:02
  • PHP FPM is storing it's socket-files in the /var/run directory by default. I just wanted to group them together so I've created a sub-directory: /var/run/php-fpm. However it's deleted after each reboot. How do I alter my starup-script to make sure it's working? I've tried to add mkdir -p /var/run/php-fpm in the begining of file, but it's not working for some reason. Aug 3, 2014 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .