无法启动php,因为它无法创建PID文件

时间:2017-08-07 06:19:01

标签: php systemd

如果我尝试启动PHP-FPM,我会收到此错误:

  

错误:无法创建PID文件(/var/run/php-fpm/php-fpm.pid):没有这样的文件或目录   错误:FPM初始化失败

我是否必须在systemctl .service文件中授予权限,以便创建文件夹和文件?

这是我的php.service文件:

[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

www.conf文件中,用户和组设置为apache。我尝试将其更改为root,然后我收到消息'尝试其他用户而不是root'。我也尝试了nginx,但后来又遇到了上一个错误。

这是我的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

编辑:我错过了/var/run/php-fpm/文件夹。我已经添加了它,现在它已经运行了。

2 个答案:

答案 0 :(得分:2)

  

错误:无法创建PID文件(/var/run/php-fpm/php-fpm.pid):没有这样的文件或目录

这意味着目录/var/run/php-fpm/不存在。您应该将此目录添加到tmpfiles.d配置中。例如,将以下行添加到/usr/lib/tmpfiles.d/php-fpm.conf

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

PIDFile文件的[Service]部分设置php.service

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

重新安装并启动服务:

systemctl disable php.service
systemctl enable php.service
systemctl start php.service

答案 1 :(得分:0)

the file will be created automatically when you run php service

RUN service php7.0-fpm start