使用root用户启动php

15 篇文章 0 订阅

一般情况下,肯定是不推荐使用root用户启动php的

但是在某些服务器管理想使用WEB的方式来控制操作的话,那么就必须要使用root用户才有权限操作


1、修改配置文件php-fpm.conf的启动用户为root,默认是nobody

我这里的php-fpm配置文件是在这里,

vim /usr/local/php7/etc/php-fpm.d/www.conf

 17 ; Default Value: none
 18 ;prefix = /path/to/pools/$pool
 19 
 20 ; Unix user/group of processes
 21 ; Note: The user is mandatory. If the group is not set, the default user's group
 22 ;       will be used.
 23 user = root
 24 group = www
 25 
 26 ; The address on which to accept FastCGI requests.
 27 ; Valid syntaxes are:
 28 ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
 29 ;                            a specific port;
 30 ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
 31 ;                            a specific port;
 32 ;   'port'                 - to listen on a TCP socket to all addresses
 33 ;                            (IPv6 and IPv4-mapped) on a specific port;
 34 ;   '/path/to/unix/socket' - to listen on a unix socket.
 35 ; Note: This value is mandatory.
 36 listen = 0.0.0.0:9000

2、启动PHP

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

启动的时候发现报错,启动不了

ERROR: [pool www] please specify user and group other than root
ERROR: FPM initialization failed

默认是不允许root用户启动的

我们可以看下--help

[root@localhost ~]# /usr/local/php7/sbin/php-fpm --help
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F [-O]]
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -h               This help
  -i               PHP information
  -m               Show compiled in modules
  -v               Version number
  -p, --prefix <dir>
                   Specify alternative prefix path to FastCGI process manager (default: /usr/local/php7).
  -g, --pid <file>
                   Specify the PID file location.
  -y, --fpm-config <file>
                   Specify alternative path to FastCGI process manager config file.
  -t, --test       Test FPM configuration and exit
  -D, --daemonize  force to run in background, and ignore daemonize option from config file
  -F, --nodaemonize
                   force to stay in foreground, and ignore daemonize option from config file
  -O, --force-stderr
                   force output to stderr in nodaemonize even if stderr is not a TTY
  -R, --allow-to-run-as-root
                   Allow pool to run as root (disabled by default)
You have new mail in /var/spool/mail/root


这里有个选项,-R, --allow-to-run-as-root,表示允许通过root启动

# /usr/local/php7/sbin/php-fpm -R

启动后验证下

[root@localhost ~]# ps aux | grep php
root      2590  0.3  0.4  30352  4296 ?        Ss   10:30   0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
root      2591  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2592  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2593  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2594  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2595  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2596  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2597  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2598  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2599  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2600  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www              
root      2601  0.0  0.2  30352  2604 ?        S    10:30   0:00 php-fpm: pool www        

这里发现已经使用root用户启动OK。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值