muyege
V2EX  ›  问与答

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

  •  
  •   muyege · Mar 29, 2017 · 4117 views
    This topic created in 3336 days ago, the information mentioned may be changed or developed.

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

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

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

    尝试指定 listen.owner listen.group 用户用户组
    muyege
        8
    muyege  
    OP
       Mar 29, 2017
    @Havee listen 到 9000 端口,socket 文件也试了,socket 文件是 root 权限,listen.owner 和 listen.group 也设置了,没什么用,改成什么都无所谓,只有当 group 为 root 或者 user 和 group 都为 root 时,才正常
    300
        9
    300  
       Mar 29, 2017   ❤️ 1
    看看 socket 文件权限,之前我就是这个问题
    muyege
        10
    muyege  
    OP
       Mar 29, 2017
    @winterbells 还是不行,只有 root 权限才能运行,其他权限改了个遍,也不好使
    Busy
        11
    Busy  
       Mar 29, 2017
    给日志吧,不能运行的日志是什么
    包括 php-fpm nginx 的日志
    muyege
        12
    muyege  
    OP
       Mar 29, 2017
    @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
        13
    muyege  
    OP
       Mar 29, 2017
    @Havee 这是 nginx 日志,php-fpm 日志没有报错
    Busy
        14
    Busy  
       Mar 29, 2017   ❤️ 1
    刚吃完饭,看了日志,第一反应是你网站目录的权限是 nobody 吗?

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

    目录所有者权限改一下,如果是虚拟机+共享盘模式,以虚拟机中 nobody 的 uid guid 为准
    muyege
        15
    muyege  
    OP
       Mar 29, 2017
    @Havee 非常感谢,解决了
    msg7086
        16
    msg7086  
       Mar 29, 2017
    nobody 读 vagrant 应该是读不到的吧……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1568 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 16:24 · PVG 00:24 · LAX 09:24 · JFK 12:24
    ♥ Do have faith in what you're doing.