让php-fpm以root的权限运行

转载 · Onlyke · 2019-05-19 · 原文
PHP

注意,本方法仅用于开发环境来解决一些奇怪问题或者方便使用,请勿在生产环境让php-fpm以root身份运行,否则一切后果自负。

  1. 编辑/etc/php/7.0/fpm/pool.d/www.conf,把user和group修改为root

    ; Unix user/group of processes 
    ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. 
    user = root 
    group = root
    
  2. 编辑/lib/systemd/system/php7.0-fpm.service,在ExecStart的 —nodaemonize前面加上 —allow-to-run-as-root,就像下面这样

    ExecStart=/usr/sbin/php-fpm7.0 --allow-to-run-as-root --nodaemonize...
    
  3. 执行命令

    systemctl daemon-reload
    
  4. 重启php-fpm即可

    service php7.0-fpm restart
    

最后,可以通过ps命令来查看效果

ps auwx | grep php

可以看到,php-fpm已经以root身份运行了。