为什么我的 PHP -fpm 必须要 root 用户启动?

2017-03-29 09:47:55 +08:00
 muyege

vagrant 安装的 centos 6.8 php 装的 7.1 web 服务器用的 openresty nginx 用户是 nobody php-fpm 也是 nobody web 目录所有者是 vagrant 死活解析不了 php 文件. 必须要把 php-fpm 放在 root 用户下启动才行 这是为什么? 求高手指导一二

3635 次点击
所在节点    问与答
16 条回复
UnisandK
2017-03-29 09:54:50 +08:00
chmod a+rw -R 试试?
muyege
2017-03-29 10:09:47 +08:00
@UnisandK 不管用,vagrant 共享目录默认是给了 vagrant 用户最大权限,除非我改成其他用户需要在配置文件里面改权限,当然我也那么做过,同样不行
CuminLo
2017-03-29 10:29:53 +08:00
PHP 是装在了共享盘上了吧?
gouchaoer
2017-03-29 10:44:23 +08:00
就是 root 启动的,只有 worker 自己 fork 出来会降到 nobody 或者 www-data 之类的
muyege
2017-03-29 10:45:32 +08:00
@CuminLo 不是,没有
muyege
2017-03-29 10:46:31 +08:00
@gouchaoer 我知道主进程是 root 启动的,现在我要把 worker 进程也改成 root 才能解析 php,就是 php-fpm 的配置文件里,user=root,group=root,才行
Havee
2017-03-29 10:56:46 +08:00
你这主题,看得好累,你 2 楼回复压根不知所云啊

问下
listen 到 socket 文件的吗?
看下这个 socket 文件权限

尝试指定 listen.owner listen.group 用户用户组
muyege
2017-03-29 11:02:59 +08:00
@Havee listen 到 9000 端口,socket 文件也试了,socket 文件是 root 权限,listen.owner 和 listen.group 也设置了,没什么用,改成什么都无所谓,只有当 group 为 root 或者 user 和 group 都为 root 时,才正常
winterbells
2017-03-29 11:12:01 +08:00
看看 socket 文件权限,之前我就是这个问题
muyege
2017-03-29 11:23:13 +08:00
@winterbells 还是不行,只有 root 权限才能运行,其他权限改了个遍,也不好使
Havee
2017-03-29 11:29:48 +08:00
给日志吧,不能运行的日志是什么
包括 php-fpm nginx 的日志
muyege
2017-03-29 12:01:00 +08:00
@Havee
2017/03/29 03:57:21 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:22 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:22 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:22 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:23 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:23 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:23 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:23 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
2017/03/29 03:57:23 [error] 4398#4398: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.1, server: www.yii.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.yii.com"
muyege
2017-03-29 12:01:20 +08:00
@Havee 这是 nginx 日志,php-fpm 日志没有报错
Havee
2017-03-29 13:26:33 +08:00
刚吃完饭,看了日志,第一反应是你网站目录的权限是 nobody 吗?

然后才发现你提问中有这句话 “目录所有者是 vagrant ”...

目录所有者权限改一下,如果是虚拟机+共享盘模式,以虚拟机中 nobody 的 uid guid 为准
muyege
2017-03-29 13:34:05 +08:00
@Havee 非常感谢,解决了
msg7086
2017-03-29 16:10:54 +08:00
nobody 读 vagrant 应该是读不到的吧……

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/351078

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX