Cannot start php because it is unable to create PID file

13,447

ERROR: Unable to create the PID file (/var/run/php-fpm/php-fpm.pid).: No such file or directory

It means that directory /var/run/php-fpm/ does not exist. You should add this directory to the tmpfiles.d configuration. For example, add the following line to /usr/lib/tmpfiles.d/php-fpm.conf:

d /var/run/php-fpm 755 root root

Set PIDFile in the [Service] section of your php.service file:

PIDFile=/var/run/php-fpm/php-fpm.pid

Re-install and start the service:

systemctl disable php.service
systemctl enable php.service
systemctl start php.service
Share:
13,447
Barsch
Author by

Barsch

Updated on July 15, 2022

Comments

  • Barsch
    Barsch almost 2 years

    If I try to start PHP-FPM I get this error:

    ERROR: Unable to create the PID file (/var/run/php-fpm/php-fpm.pid).: No such file or directory ERROR: FPM initialization failed

    Do I have to give permissions in the systemctl .service file so it can create the folder and file?

    This is my php.service file:

    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target
    
    [Service]
    Type=notify
    EnvironmentFile=/etc/opt/remi/php70/sysconfig/php-fpm
    ExecStart=/opt/remi/php70/root/usr/sbin/php-fpm --nodaemonize
    ExecReload=/bin/kill -USR2 $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    

    In the www.conf file there is a user and group set as apache. I tried changing it to root, but then I get the message 'try another user than root'. I've also tried nginx, but then again I got the previous error.

    Here is my www.conf

    ; Start a new pool named 'www'.
    ; the variable $pool can we used in any directive and will be replaced by the
    ; pool name ('www' here)
    [www]
    
    ; Per pool prefix
    ; It only applies on the following directives:
    ; - 'access.log'
    ; - 'slowlog'
    ; - 'listen' (unixsocket)
    ; - 'chroot'
    ; - 'chdir'
    ; - 'php_values'
    ; - 'php_admin_values'
    ; When not set, the global prefix (or @php_fpm_prefix@) applies instead.
    ; Note: This directive can also be relative to the global prefix.
    ; Default Value: none
    ;prefix = /path/to/pools/$pool
    
    ; Unix user/group of processes
    ; Note: The user is mandatory. If the group is not set, the default user's group
    ;       will be used.
    ; RPM: apache Choosed to be able to access some dir as httpd
    user = apache
    ; RPM: Keep a group allowed to write in log dir.
    group = apache
    
    ; The address on which to accept FastCGI requests.
    ; Valid syntaxes are:
    ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
    ;                            a specific port;
    ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
    ;                            a specific port;
    ;   'port'                 - to listen on a TCP socket to all addresses
    ;                            (IPv6 and IPv4-mapped) on a specific port;
    ;   '/path/to/unix/socket' - to listen on a unix socket.
    ; Note: This value is mandatory.
    listen = 127.0.0.1:9000
    
    ; Set listen(2) backlog.
    ; Default Value: 511
    ;listen.backlog = 511
    
    ; Set permissions for unix socket, if one is used. In Linux, read/write
    ; permissions must be set in order to allow connections from a web server.
    ; Default Values: user and group are set as the running user
    ;                 mode is set to 0660
    ;listen.owner = nobody
    ;listen.group = nobody
    ;listen.mode = 0660
    
    ; When POSIX Access Control Lists are supported you can set them using
    ; these options, value is a comma separated list of user/group names.
    ; When set, listen.owner and listen.group are ignored
    ;listen.acl_users = apache,nginx
    ;listen.acl_groups =
    
    ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
    ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
    ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
    ; must be separated by a comma. If this value is left blank, connections will be
    ; accepted from any ip address.
    ; Default Value: any
    "www.conf" 422L, 18812C
    

    EDIT: I was missing the /var/run/php-fpm/folder. I've added it, now it runs.

    • Professor Abronsius
      Professor Abronsius over 6 years
      can you include your config?
    • Barsch
      Barsch over 6 years
      I've edited the .service file and the user and group of my www.conf file to my post, or which config did you mean?
    • Ruslan Osmanov
      Ruslan Osmanov over 6 years
      @Barsch, try to add PIDFile=/var/run/php-fpm/php-fpm.pid to the [Service] section
    • Barsch
      Barsch over 6 years
      @RuslanOsmanov I've tried it. Still the same error. In /var/run/ there is no folder php-fpm. But I guess it should be created at the start/installation of php?
    • Barsch
      Barsch over 6 years
      added this folder, now it starts
    • Remi Collet
      Remi Collet over 6 years
      default PID location from /etc/opt/remi/php70/php-fpm.conf (default configuration) is pid = /var/opt/remi/php70/run/php-fpm/php-fpm.pid which should exists (own by the package). @RuslanOsmanov: PIDfile in unit file is uneeded (type=notify)
  • Barsch
    Barsch over 6 years
    I get the following message: Job for php70-php-fpm.service failed because the control process exited with error code. See "systemctl status php70-php-fpm.service" and "journalctl -xe" for details.
  • Bara' ayyash
    Bara' ayyash over 6 years
    which php version do you use ?
  • Barsch
    Barsch over 6 years
    I use php7 on this server
  • Bara' ayyash
    Bara' ayyash over 6 years
    try adding php56-php-fpm and php-fpm to variable php_packages
  • Barsch
    Barsch over 6 years
    noob question: how do I do that, and what does it do?