在systemd中配置php-fpm.service

vim /etc/systemd/system/php-fpm.service

[Unit]

Description=PHP-FPM

After=network.target syslog.target

[Install]

WantedBy=default.target

# Alias=php-fpm.service 不要设置别名。如果本文件名和Alias同名,则会导致systemctl enable php71-fpm报错:Failed to execute operation: Invalid argument

[Service]

#User=nobody

#Group=nobody

#User and Group can be set in the php-fpm configure file

# 2020-04-24更新:参考PHP默认提供的配置文件,使用Type=notify
Type=notify
#Type=forking
## PIDFile=/usr/local/php7/var/run/php-fpm.pid  不需要在这里指定pid文件位置,需要到php-fpm.conf文件中指定

ExecStart=/usr/local/php7/sbin/php-fpm

ExecStop=/bin/kill -INT $MAINPID

ExecReload=/bin/kill -USR2 $MAINPID

保存设置
systemctl daemon-reload

启动php-fpm.service
systemctl start php-fpm

systemctl enable php-fpm设置为开机启动

如果启动失败,请查看日志,常见错误都是权限问题,比如pid目录和php-fpm设置的log目录没有写权限等

 

PS:其实在编译PHP后,会自动生成配置文件,位置:php-${PHP_VERSION}/sapi/fpm/php-fpm.service ,然后直接把这个文件拷贝到/etc/systemd/system 目录即可

《在systemd中配置php-fpm.service》上有1条评论

回复 tom.chang 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

*