linux下php-fpm以root身份启动设置

小浪SEO博客 专注SEO优化思维、SEO技术的实战分享类博客~

php-fpm是php的一个加速 功能了,我们通常是以apache来启动php-fpm了,但今天小编来为各位介绍php-fpm使用root启动的教程,希望文章能够帮助到各位.

为了安全php-fpm默认是以apache用户启动的:

  1. [root@chaoge~]#ps-aux|grepphp-fpm
  2. Warning:badsyntax,perhapsabogus'-'?See/usr/share/doc/procps-3.2.8/FAQ
  3. root45390.00.02055523716?Ss10:220:00php-fpm:masterprocess(/etc/php-fpm.conf)
  4. apache45400.00.02055523332?S10:220:00php-fpm:poolwww
  5. apache45410.00.02055523332?S10:220:00php-fpm:poolwww
  6. apache45420.00.02055523332?S10:220:00php-fpm:poolwww
  7. apache45430.00.02055523332?S10:220:00php-fpm:poolwww
  8. apache45440.00.02055523332?S10:220:00php-fpm:poolwww
  9. root45560.00.0103248888pts/1S+10:220:00grepphp-fpm

网上一堆文章说要以root身份启动需要设置一堆非常复杂的程序,并且甚至有人说不能以root身份启动,既然是php-fpm程序,所以应该先找配置文件,于是打开默认的配置文件,具体你得看你的默认配置文件路径在哪.

/etc/php-fpm.d/www.conf

这是我机器上的,找到:

  1. ;RPM:apacheChoosedtobeabletoaccesssomedirashttpd
  2. user=apache
  3. //改成
  4. ;RPM:apacheChoosedtobeabletoaccesssomedirashttpd
  5. user=root

重新启动php-fpm:

  1. [root@chaoge~]#ps-le|grepphp-fpm
  2. 1S0497410800-51388ep_pol?00:00:00php-fpm
  3. 5S48497549740800-51388inet_c?00:00:00php-fpm
  4. 5S48497649740800-51388inet_c?00:00:00php-fpm
  5. 5S48497749740800-51388inet_c?00:00:00php-fpm
  6. 5S48497849740800-51388inet_c?00:00:00php-fpm
  7. 5S48503549740800-51388inet_c?00:00:00php-fpm
  8. [root@chaoge~]#kill-QUIT5035
  9. [root@chaoge~]#php-fpm
  10. [17-Apr-201510:33:38]ERROR:[poolwww]pleasespecifyuserandgroupotherthanroot//phpfensi.com
  11. [17-Apr-201510:33:38]ERROR:FPMinitializationfailed
  12. [root@chaoge~]#

报错了,提示运行php-fpm运行用户和组只能选择其它的除了root以外,于是查看php-fpm文档,会发现其中一个选项:-R

  1. [root@chaoge~]#php-fpm--help
  2. Usage:php[-n][-e][-h][-i][-m][-v][-t][-p<prefix>][-g<pid>][-c<file>][-dfoo[=bar]][-y<file>][-D][-F]
  3. -c<path>|<file>Lookforphp.inifileinthisdirectory
  4. -nNophp.inifilewillbeused
  5. -dfoo[=bar]DefineINIentryfoowithvalue'bar'
  6. -eGenerateextendedinformationfordebugger/profiler
  7. -hThishelp
  8. -iPHPinformation
  9. -mShowcompiledinmodules
  10. -vVersionnumber
  11. -p,--prefix<dir>
  12. SpecifyalternativeprefixpathtoFastCGIprocessmanager(default:/usr).
  13. -g,--pid<file>
  14. SpecifythePIDfilelocation.
  15. -y,--fpm-config<file>
  16. SpecifyalternativepathtoFastCGIprocessmanagerconfigfile.
  17. -t,--testTestFPMconfigurationandexit
  18. -D,--daemonizeforcetoruninbackground,andignoredaemonizeoptionfromconfigfile
  19. -F,--nodaemonize
  20. forcetostayinforeground,andignoredaemonizeoptionfromconfigfile
  21. -R,--allow-to-run-as-root
  22. Allowpooltorunasroot(disabledbydefault)

于是我们试着启动的时候加上这个参数试一试.

  1. [root@chaoge~]#php-fpm-R
  2. [root@chaoge~]#ps-aux|grepphp-fpm
  3. Warning:badsyntax,perhapsabogus'-'?See/usr/share/doc/procps-3.2.8/FAQ
  4. root54970.00.02055523712?Ss10:360:00php-fpm:masterprocess(/etc/php-fpm.conf)
  5. root54980.00.02055523196?S10:360:00php-fpm:poolwww
  6. root54990.00.02055523196?S10:360:00php-fpm:poolwww
  7. root55000.00.02055523196?S10:360:00php-fpm:poolwww
  8. root55010.00.02055523200?S10:360:00php-fpm:poolwww
  9. root55020.00.02055523200?S10:360:00php-fpm:poolwww
  10. root55240.00.0103252888pts/1S+10:360:00grepphp-fpm

成功启动了,测试一下,以root用户写了一个shell脚本保存在root宿主目录下,php里exec写好的脚本正常运行.

相关广告
  • linux下php-fpm以root身份启动设置 linux下php-fpm以root身份启动设置 linux下php-fpm以root身份启动设置
相关阅读

linux下php-fpm以root身份启动设置

2019/10/10 17:45:21 | 谷歌SEO算法 | 5G标准出炉