php使用root用户启动

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

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

 

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

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

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

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

 

2、启动PHP

 

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

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

 

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

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

我们可以看下--help

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

 

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

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

启动后验证下

 

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


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

posted @ 2018-04-13 19:29  大数据从业者FelixZh  阅读(3426)  评论(0编辑  收藏  举报