linux下php-fpm以root身份启动设置
2019/10/10/17:45:21 阅读:1794 来源:谷歌SEO算法 标签:
5G标准出炉
php-fpm是php的一个加速 功能了,我们通常是以apache来启动php-fpm了,但今天小编来为各位介绍php-fpm使用root启动的教程,希望文章能够帮助到各位.
为了安全php-fpm默认是以apache用户启动的:
- [root@chaoge~]#ps-aux|grepphp-fpm
- Warning:badsyntax,perhapsabogus'-'?See/usr/share/doc/procps-3.2.8/FAQ
- root45390.00.02055523716?Ss10:220:00php-fpm:masterprocess(/etc/php-fpm.conf)
- apache45400.00.02055523332?S10:220:00php-fpm:poolwww
- apache45410.00.02055523332?S10:220:00php-fpm:poolwww
- apache45420.00.02055523332?S10:220:00php-fpm:poolwww
- apache45430.00.02055523332?S10:220:00php-fpm:poolwww
- apache45440.00.02055523332?S10:220:00php-fpm:poolwww
- root45560.00.0103248888pts/1S+10:220:00grepphp-fpm
网上一堆文章说要以root身份启动需要设置一堆非常复杂的程序,并且甚至有人说不能以root身份启动,既然是php-fpm程序,所以应该先找配置文件,于是打开默认的配置文件,具体你得看你的默认配置文件路径在哪.
/etc/php-fpm.d/www.conf
这是我机器上的,找到:
- ;RPM:apacheChoosedtobeabletoaccesssomedirashttpd
- user=apache
- //改成
- ;RPM:apacheChoosedtobeabletoaccesssomedirashttpd
- user=root
重新启动php-fpm:
- [root@chaoge~]#ps-le|grepphp-fpm
- 1S0497410800-51388ep_pol?00:00:00php-fpm
- 5S48497549740800-51388inet_c?00:00:00php-fpm
- 5S48497649740800-51388inet_c?00:00:00php-fpm
- 5S48497749740800-51388inet_c?00:00:00php-fpm
- 5S48497849740800-51388inet_c?00:00:00php-fpm
- 5S48503549740800-51388inet_c?00:00:00php-fpm
- [root@chaoge~]#kill-QUIT5035
- [root@chaoge~]#php-fpm
- [17-Apr-201510:33:38]ERROR:[poolwww]pleasespecifyuserandgroupotherthanroot//phpfensi.com
- [17-Apr-201510:33:38]ERROR:FPMinitializationfailed
- [root@chaoge~]#
报错了,提示运行php-fpm运行用户和组只能选择其它的除了root以外,于是查看php-fpm文档,会发现其中一个选项:-R
- [root@chaoge~]#php-fpm--help
- Usage:php[-n][-e][-h][-i][-m][-v][-t][-p<prefix>][-g<pid>][-c<file>][-dfoo[=bar]][-y<file>][-D][-F]
- -c<path>|<file>Lookforphp.inifileinthisdirectory
- -nNophp.inifilewillbeused
- -dfoo[=bar]DefineINIentryfoowithvalue'bar'
- -eGenerateextendedinformationfordebugger/profiler
- -hThishelp
- -iPHPinformation
- -mShowcompiledinmodules
- -vVersionnumber
- -p,--prefix<dir>
- SpecifyalternativeprefixpathtoFastCGIprocessmanager(default:/usr).
- -g,--pid<file>
- SpecifythePIDfilelocation.
- -y,--fpm-config<file>
- SpecifyalternativepathtoFastCGIprocessmanagerconfigfile.
- -t,--testTestFPMconfigurationandexit
- -D,--daemonizeforcetoruninbackground,andignoredaemonizeoptionfromconfigfile
- -F,--nodaemonize
- forcetostayinforeground,andignoredaemonizeoptionfromconfigfile
- -R,--allow-to-run-as-root
- Allowpooltorunasroot(disabledbydefault)
于是我们试着启动的时候加上这个参数试一试.
- [root@chaoge~]#php-fpm-R
- [root@chaoge~]#ps-aux|grepphp-fpm
- Warning:badsyntax,perhapsabogus'-'?See/usr/share/doc/procps-3.2.8/FAQ
- root54970.00.02055523712?Ss10:360:00php-fpm:masterprocess(/etc/php-fpm.conf)
- root54980.00.02055523196?S10:360:00php-fpm:poolwww
- root54990.00.02055523196?S10:360:00php-fpm:poolwww
- root55000.00.02055523196?S10:360:00php-fpm:poolwww
- root55010.00.02055523200?S10:360:00php-fpm:poolwww
- root55020.00.02055523200?S10:360:00php-fpm:poolwww
- root55240.00.0103252888pts/1S+10:360:00grepphp-fpm
成功启动了,测试一下,以root用户写了一个shell脚本保存在root宿主目录下,php里exec写好的脚本正常运行.
热门评论