php使用root用户启动
一般情况下,肯定是不推荐使用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。
欢迎关注微信公众号:大数据从业者