php-fpm 启动失败 Permission denied

举报
林欣 发表于 2025/09/21 22:46:05 2025/09/21
【摘要】 Sep 12 12:17:16 centos7-os systemd[1]: start request repeated too quickly for php-fpm.serviceSep 12 12:17:16 centos7-os systemd[1]: Failed to start The PHP FastCGI Process Manager.Sep 12 12:17:16 c...
Sep 12 12:17:16 centos7-os systemd[1]: start request repeated too quickly for php-fpm.service
Sep 12 12:17:16 centos7-os systemd[1]: Failed to start The PHP FastCGI Process Manager.
Sep 12 12:17:16 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service failed.
[root@centos7-os var]# /usr/local/php8/sbin/php-fpm -t
[12-Sep-2025 12:18:24] NOTICE: configuration file /usr/local/php8/etc/php-fpm.conf test is successful
[root@centos7-os var]# journalctl -u php-fpm --no-pager -n 50
-- Logs begin at Sun 2025-05-11 04:23:29 CST, end at Fri 2025-09-12 12:20:01 CST. --
Sep 12 12:17:15 centos7-os systemd[1]: Started The PHP FastCGI Process Manager.
Sep 12 12:17:15 centos7-os systemd[1]: Starting The PHP FastCGI Process Manager...
Sep 12 12:17:15 centos7-os php-fpm[25541]: [12-Sep-2025 12:17:15] ERROR: failed to open error_log (/usr/local/php8/var/log/php-fpm.log): Permission denied (13)
Sep 12 12:17:15 centos7-os php-fpm[25541]: [12-Sep-2025 12:17:15] ERROR: failed to post process the configuration
Sep 12 12:17:15 centos7-os php-fpm[25541]: [12-Sep-2025 12:17:15] ERROR: FPM initialization failed
Sep 12 12:17:15 centos7-os systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Sep 12 12:17:15 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:15 centos7-os systemd[1]: php-fpm.service failed.
Sep 12 12:17:15 centos7-os systemd[1]: php-fpm.service holdoff time over, scheduling restart.
Sep 12 12:17:15 centos7-os systemd[1]: Started The PHP FastCGI Process Manager.
Sep 12 12:17:15 centos7-os systemd[1]: Starting The PHP FastCGI Process Manager...
Sep 12 12:17:15 centos7-os php-fpm[25544]: [12-Sep-2025 12:17:15] ERROR: failed to open error_log (/usr/local/php8/var/log/php-fpm.log): Permission denied (13)
Sep 12 12:17:15 centos7-os php-fpm[25544]: [12-Sep-2025 12:17:15] ERROR: failed to post process the configuration
Sep 12 12:17:15 centos7-os php-fpm[25544]: [12-Sep-2025 12:17:15] ERROR: FPM initialization failed
Sep 12 12:17:15 centos7-os systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Sep 12 12:17:15 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:15 centos7-os systemd[1]: php-fpm.service failed.
Sep 12 12:17:15 centos7-os systemd[1]: php-fpm.service holdoff time over, scheduling restart.
Sep 12 12:17:15 centos7-os systemd[1]: Started The PHP FastCGI Process Manager.
Sep 12 12:17:15 centos7-os systemd[1]: Starting The PHP FastCGI Process Manager...
Sep 12 12:17:16 centos7-os php-fpm[25546]: [12-Sep-2025 12:17:16] ERROR: failed to open error_log (/usr/local/php8/var/log/php-fpm.log): Permission denied (13)
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Sep 12 12:17:16 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service failed.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service holdoff time over, scheduling restart.
Sep 12 12:17:16 centos7-os systemd[1]: Started The PHP FastCGI Process Manager.
Sep 12 12:17:16 centos7-os systemd[1]: Starting The PHP FastCGI Process Manager...
Sep 12 12:17:16 centos7-os php-fpm[25548]: [12-Sep-2025 12:17:16] ERROR: failed to open error_log (/usr/local/php8/var/log/php-fpm.log): Permission denied (13)
Sep 12 12:17:16 centos7-os php-fpm[25548]: [12-Sep-2025 12:17:16] ERROR: failed to post process the configuration
Sep 12 12:17:16 centos7-os php-fpm[25548]: [12-Sep-2025 12:17:16] ERROR: FPM initialization failed
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Sep 12 12:17:16 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service failed.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service holdoff time over, scheduling restart.
Sep 12 12:17:16 centos7-os systemd[1]: Started The PHP FastCGI Process Manager.
Sep 12 12:17:16 centos7-os systemd[1]: Starting The PHP FastCGI Process Manager...
Sep 12 12:17:16 centos7-os php-fpm[25554]: [12-Sep-2025 12:17:16] ERROR: failed to open error_log (/usr/local/php8/var/log/php-fpm.log): Permission denied (13)
Sep 12 12:17:16 centos7-os php-fpm[25554]: [12-Sep-2025 12:17:16] ERROR: failed to post process the configuration
Sep 12 12:17:16 centos7-os php-fpm[25554]: [12-Sep-2025 12:17:16] ERROR: FPM initialization failed
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Sep 12 12:17:16 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service failed.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service holdoff time over, scheduling restart.
Sep 12 12:17:16 centos7-os systemd[1]: start request repeated too quickly for php-fpm.service
Sep 12 12:17:16 centos7-os systemd[1]: Failed to start The PHP FastCGI Process Manager.
Sep 12 12:17:16 centos7-os systemd[1]: Unit php-fpm.service entered failed state.
Sep 12 12:17:16 centos7-os systemd[1]: php-fpm.service failed.

journalctl 的日志来看,php-fpm 启动失败的根本原因是权限问题,具体表现为:

ERROR: failed to open error_log (/usr/local/php8/var/log/php-fpm.log): Permission denied (13)

php-fpm 进程无法写入日志文件 /usr/local/php8/var/log/php-fpm.log,导致服务初始化失败。


解决方案

1. 检查并修复日志文件权限

# 确保日志目录存在
mkdir -p /usr/local/php8/var/log/

# 修改日志文件权限(假设 php-fpm 运行用户是 nginx 或 apache)
chown -R nginx:nginx /usr/local/php8/var/log/
chmod 755 /usr/local/php8/var/log/

# 如果日志文件不存在,手动创建并设置权限
touch /usr/local/php8/var/log/php-fpm.log
chown nginx:nginx /usr/local/php8/var/log/php-fpm.log
chmod 644 /usr/local/php8/var/log/php-fpm.log

2. 检查 php-fpm 运行用户

查看 php-fpm.confwww.conf(通常在 /usr/local/php8/etc/php-fpm.d/)确认运行用户:

grep -E 'user|group' /usr/local/php8/etc/php-fpm.conf
grep -E 'user|group' /usr/local/php8/etc/php-fpm.d/*.conf

确保该用户(如 nginxapachewww-data)对日志目录有写入权限。

3. 检查 SELinux 状态(如果启用)

# 查看 SELinux 状态
getenforce

# 如果启用(Enforcing),尝试临时放宽限制
setenforce 0

# 测试 php-fpm 是否能启动
systemctl start php-fpm

# 如果成功,说明是 SELinux 问题,需调整策略
chcon -R -t httpd_sys_rw_content_t /usr/local/php8/var/log/
setenforce 1  # 重新启用 SELinux

4. 清理残留进程并重启服务

# 杀死残留的 php-fpm 进程
pkill php-fpm

# 重置 systemd 启动限制
systemctl reset-failed php-fpm

# 重新启动服务
systemctl start php-fpm
systemctl status php-fpm

5. 检查其他可能的问题

  • PID 文件路径:确保 php-fpm.conf 中的 pid 路径(如 /run/php-fpm/php-fpm.pid)存在且可写:
    mkdir -p /run/php-fpm
    chown nginx:nginx /run/php-fpm
    
  • 端口冲突:确认 9000 端口未被占用:
    netstat -tulnp | grep 9000
    

验证修复

# 检查日志是否有新错误
tail -f /usr/local/php8/var/log/php-fpm.log

# 确认服务状态
systemctl status php-fpm

总结

  • 根本原因php-fpm 进程用户无权写入日志文件 /usr/local/php8/var/log/php-fpm.log
  • 关键修复步骤
    1. 修正日志文件及目录的权限(chown + chmod)。
    2. 确认 php-fpm 运行用户与权限匹配。
    3. 处理 SELinux 限制(如启用)。
    4. 清理残留进程并重启服务。
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。