如何最接近rpm的安装方式去编译安装最新的php-fpm推荐

1 前言

笔者非常不喜欢某些人编译安装的软件,维护起来非常缺乏rpm安装的那种规范感觉,于是笔者参阅官方的编译安装教程以及对比分析rpm安装的目录布置结构,完成以下安装。

2 安装PHP-FPM

2.1 环境配置

2.1.1 安装解压工具

yuminstall-ybzip2

2.1.2 配置编译环境

yum-yinstallgccgcc-c++makeexpat-devel

2.1.3 下载php二进制安装包

cd~wgethttp://cn2.php.net/distributions/php-7.1.12.tar.bz2

注:具体的下载页面请参阅

http://sg2.php.net/downloads.php

2.1.4 创建运行用户

groupadd-g48apacheuseradd-u48-g48-d/usr/share/httpd-s/sbin/nologinapache

2.1.5 预建目录

mkdir/var/log/php-fpm/mkdir/run/php-fpm/

2.1.6 配置防火墙

firewall-cmd –permanent –add-port 9000/tcp

firewall-cmd –reload

firewall-cmd –list-all

2.2 编译安装

2.2.1 解压安装包

tar-xfphp-7.1.12.tar.bz2

2.2.2 安装前构建

cdphp-7.1.12 ./configure--bindir=/usr/sbin/\--sbindir=/usr/sbin/\--sysconfdir=/etc/\--libdir=/usr/lib64/\--mandir=/usr/share/man/\--includedir=/usr/include/\--with-fpm-user=apache\--with-fpm-group=apache\--enable-fpm\--with-mysqli

根据提示解决安装的依赖关系

yuminstall-ylibxml2-devel

2.2.3 编译并安装

makemakeinstall|teeinstall.log

2.3 配置FPM

2.3.1 配置php.ini

cpphp.ini-development/etc/php.ini

2.3.2 防止空文件递给PHP-FPM后端

vim/etc/php.ini

修改以下参数:

cgi.fix_pathinfo=0

注:可防任意脚本注入

2.3.3 创建配置

vim/etc/php-fpm.conf

加入如下配置:

;;;;;;;;;;;;;;;;;;;;;;FPMConfiguration;;;;;;;;;;;;;;;;;;;;;;;AllrelativepathsinthisconfigurationfilearerelativetoPHP sinstall;prefix.;Includeoneormorefiles.Ifglob(3)exists,itisusedtoincludeabunchof;filesfromaglob(3)pattern.Thisdirectivecanbeusedeverywhereinthe;file.include=/etc/php-fpm.d/*.conf;;;;;;;;;;;;;;;;;;;GlobalOptions;;;;;;;;;;;;;;;;;;;[global];Pidfile;DefaultValue:nonepid=/run/php-fpm/php-fpm.pid;Errorlogfile;DefaultValue:/var/log/php-fpm.logerror_log=/var/log/php-fpm/error.log;Loglevel;PossibleValues:alert,error,warning,notice,debug;DefaultValue:notice;log_level=notice;IfthisnumberofchildprocessesexitwithSIGSEGVorSIGBUSwithinthetime;intervalsetbyemergency_restart_intervalthenFPMwillrestart.Avalue;of 0 means Off .;DefaultValue:0;emergency_restart_threshold=0;Intervaloftimeusedbyemergency_restart_intervaltodeterminewhen;agracefulrestartwillbeinitiated.Thiscanbeusefultoworkaround;accidentalcorruptionsinanaccelerator ssharedmemory.;AvailableUnits:s(econds),m(inutes),h(ours),ord(ays);DefaultUnit:seconds;DefaultValue:0;emergency_restart_interval=0;Timelimitforchildprocessestowaitforareactiononsignalsfrommaster.;Availableunits:s(econds),m(inutes),h(ours),ord(ays);DefaultUnit:seconds;DefaultValue:0;process_control_timeout=0;SendFPMtobackground.Setto no tokeepFPMinforegroundfordebugging.;DefaultValue:yesdaemonize=no;;;;;;;;;;;;;;;;;;;;;PoolDefinitions;;;;;;;;;;;;;;;;;;;;;;See/etc/php-fpm.d/*.conf

创建以下配置文件:

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

加入如下配置:

;Startanewpoolnamed www .[www];TheaddressonwhichtoacceptFastCGIrequests.;Validsyntaxesare:; ip.add.re.ss:port -tolistenonaTCPsockettoaspecificaddresson;aspecificport;; port -tolistenonaTCPsockettoalladdressesona;specificport;; /path/to/unix/socket -tolistenonaunixsocket.;Note:Thisvalueismandatory.listen=127.0.0.1:9000;Setlisten(2)backlog.Avalueof -1 meansunlimited.;DefaultValue:-1;listen.backlog=-1;Listofipv4addressesofFastCGIclientswhichareallowedtoconnect.;EquivalenttotheFCGI_WEB_SERVER_ADDRSenvironmentvariableintheoriginal;PHPFCGI(5.2.2+).Makessenseonlywithatcplisteningsocket.Eachaddress;mustbeseparatedbyacomma.Ifthisvalueisleftblank,connectionswillbe;acceptedfromanyipaddress.;DefaultValue:anylisten.allowed_clients=127.0.0.1;Setpermissionsforunixsocket,ifoneisused.InLinux,read/write;permissionsmustbesetinordertoallowconnectionsfromawebserver.Many;BSD-derivedsystemsallowconnectionsregardlessofpermissions.;DefaultValues:userandgrouparesetastherunninguser;modeissetto0666;listen.owner=nobody;listen.group=nobody;listen.mode=0666;Unixuser/groupofprocesses;Note:Theuserismandatory.Ifthegroupisnotset,thedefaultuser sgroup;willbeused.;RPM:apacheChoosedtobeabletoaccesssomedirashttpduser=apache;RPM:Keepagroupallowedtowriteinlogdir.group=apache;Choosehowtheprocessmanagerwillcontrolthenumberofchildprocesses.;PossibleValues:;static-afixednumber(pm.max_children)ofchildprocesses;;dynamic-thenumberofchildprocessesaresetdynamicallybasedonthe;followingdirectives:;pm.max_children-themaximumnumberofchildrenthatcan;bealiveatthesametime.;pm.start_servers-thenumberofchildrencreatedonstartup.;pm.min_spare_servers-theminimumnumberofchildrenin idle ;state(waitingtoprocess).Ifthenumber;of idle processesislessthanthis;numberthensomechildrenwillbecreated.;pm.max_spare_servers-themaximumnumberofchildrenin idle ;state(waitingtoprocess).Ifthenumber;of idle processesisgreaterthanthis;numberthensomechildrenwillbekilled.;Note:Thisvalueismandatory.pm=dynamic;Thenumberofchildprocessestobecreatedwhenpmissetto static andthe;maximumnumberofchildprocessestobecreatedwhenpmissetto dynamic .;Thisvaluesetsthelimitonthenumberofsimultaneousrequeststhatwillbe;served.EquivalenttotheApacheMaxClientsdirectivewithmpm_prefork.;EquivalenttothePHP_FCGI_CHILDRENenvironmentvariableintheoriginalPHP;CGI.;Note:Usedwhenpmissettoeither static or dynamic ;Note:Thisvalueismandatory.pm.max_children=50;Thenumberofchildprocessescreatedonstartup.;Note:Usedonlywhenpmissetto dynamic ;DefaultValue:min_spare_servers+(max_spare_servers-min_spare_servers)/2pm.start_servers=5;Thedesiredminimumnumberofidleserverprocesses.;Note:Usedonlywhenpmissetto dynamic ;Note:Mandatorywhenpmissetto dynamic pm.min_spare_servers=5;Thedesiredmaximumnumberofidleserverprocesses.;Note:Usedonlywhenpmissetto dynamic ;Note:Mandatorywhenpmissetto dynamic pm.max_spare_servers=35;Thenumberofrequestseachchildprocessshouldexecutebeforerespawning.;Thiscanbeusefultoworkaroundmemoryleaksin3rdpartylibraries.For;endlessrequestprocessingspecify 0 .EquivalenttoPHP_FCGI_MAX_REQUESTS.;DefaultValue:0;pm.max_requests=500;TheURItoviewtheFPMstatuspage.Ifthisvalueisnotset,noURIwillbe;recognizedasastatuspage.Bydefault,thestatuspageshowsthefollowing;information:;acceptedconn-thenumberofrequestacceptedbythepool;;pool-thenameofthepool;;processmanager-staticordynamic;;idleprocesses-thenumberofidleprocesses;;activeprocesses-thenumberofactiveprocesses;;totalprocesses-thenumberofidle+activeprocesses.;Thevaluesof idleprocesses , activeprocesses and totalprocesses are;updatedeachsecond.Thevalueof acceptedconn isupdatedinrealtime.;Exampleoutput:;acceptedconn:12073;pool:www;processmanager:static;idleprocesses:35;activeprocesses:65;totalprocesses:100;Bydefaultthestatuspageoutputisformattedastext/plain.Passingeither; html or json asaquerystringwillreturnthecorrespondingoutput;syntax.Example:;http://www.foo.bar/status;http://www.foo.bar/status?json;http://www.foo.bar/status?html;Note:Thevaluemuststartwithaleadingslash(/).Thevaluecanbe;anything,butitmaynotbeagoodideatousethe.phpextensionorit;mayconflictwitharealPHPfile.;DefaultValue:notset;pm.status_path=/status;ThepingURItocallthemonitoringpageofFPM.Ifthisvalueisnotset,no;URIwillberecognizedasapingpage.Thiscouldbeusedtotestfromoutside;thatFPMisaliveandresponding,orto;-createagraphofFPMavailability(rrdorsuch);;-removeaserverfromagroupifitisnotresponding(loadbalancing);;-triggeralertsfortheoperatingteam(24/7).;Note:Thevaluemuststartwithaleadingslash(/).Thevaluecanbe;anything,butitmaynotbeagoodideatousethe.phpextensionorit;mayconflictwitharealPHPfile.;DefaultValue:notset;ping.path=/ping;Thisdirectivemaybeusedtocustomizetheresponseofapingrequest.The;responseisformattedastext/plainwitha200responsecode.;DefaultValue:pong;ping.response=pong;Thetimeoutforservingasinglerequestafterwhichtheworkerprocesswill;bekilled.Thisoptionshouldbeusedwhenthe max_execution_time inioption;doesnotstopscriptexecutionforsomereason.Avalueof 0 means off .;Availableunits:s(econds)(default),m(inutes),h(ours),ord(ays);DefaultValue:0;request_terminate_timeout=0;ThetimeoutforservingasinglerequestafterwhichaPHPbacktracewillbe;dumpedtothe slowlog file.Avalueof 0s means off .;Availableunits:s(econds)(default),m(inutes),h(ours),ord(ays);DefaultValue:0;request_slowlog_timeout=0;Thelogfileforslowrequests;DefaultValue:notset;Note:slowlogismandatoryifrequest_slowlog_timeoutissetslowlog=/var/log/php-fpm/www-slow.log;Setopenfiledescriptorrlimit.;DefaultValue:systemdefinedvalue;rlimit_files=1024;Setmaxcoresizerlimit.;PossibleValues: unlimited oranintegergreaterorequalto0;DefaultValue:systemdefinedvalue;rlimit_core=0;Chroottothisdirectoryatthestart.Thisvaluemustbedefinedasan;absolutepath.Whenthisvalueisnotset,chrootisnotused.;Note:chrootingisagreatsecurityfeatureandshouldbeusedwhenever;possible.However,allPHPpathswillberelativetothechroot;(error_log,sessions.save_path,...).;DefaultValue:notset;chroot=;Chdirtothisdirectoryatthestart.Thisvaluemustbeanabsolutepath.;DefaultValue:currentdirectoryor/whenchroot;chdir=/var/www;Redirectworkerstdoutandstderrintomainerrorlog.Ifnotset,stdoutand;stderrwillberedirectedto/dev/nullaccordingtoFastCGIspecs.;DefaultValue:no;catch_workers_output=yes;LimitstheextensionsofthemainscriptFPMwillallowtoparse.Thiscan;preventconfigurationmistakesonthewebserverside.Youshouldonlylimit;FPMto.phpextensionstopreventmalicioususerstouseotherextensionsto;exectutephpcode.;Note:setanemptyvaluetoallowallextensions.;DefaultValue:.php;security.limit_extensions=.php.php3.php4.php5;PassenvironmentvariableslikeLD_LIBRARY_PATH.All$VARIABLEsaretakenfrom;thecurrentenvironment.;DefaultValue:cleanenv;env[HOSTNAME]=$HOSTNAME;env[PATH]=/usr/local/bin:/usr/bin:/bin;env[TMP]=/tmp;env[TMPDIR]=/tmp;env[TEMP]=/tmp;Additionalphp.inidefines,specifictothispoolofworkers.Thesesettings;overwritethevaluespreviouslydefinedinthephp.ini.Thedirectivesarethe;sameasthePHPSAPI:;php_value/php_flag-youcansetclassicinidefineswhichcan;beoverwrittenfromPHPcall ini_set .;php_admin_value/php_admin_flag-thesedirectiveswon tbeoverwrittenby;PHPcall ini_set ;Forphp_*flag,validvaluesareon,off,1,0,true,false,yesorno.;Defining extension willloadthecorrespondingsharedextensionfrom;extension_dir.Defining disable_functions or disable_classes willnot;overwritepreviouslydefinedphp.inivalues,butwillappendthenewvalue;instead.;DefaultValue:nothingisdefinedbydefaultexceptthevaluesinphp.iniand;specifiedatstartupwiththe-dargument;php_admin_value[sendmail_path]=/usr/sbin/sendmail-t-i-fwww@my.domain.com;php_flag[display_errors]=offphp_admin_value[error_log]=/var/log/php-fpm/www-error.logphp_admin_flag[log_errors]=on;php_admin_value[memory_limit]=128M;Setsessionpathtoadirectoryownedbyprocessuserphp_value[session.save_handler]=filesphp_value[session.save_path]=/var/lib/php/session

2.3.4 测试fpm启动

/usr/sbin/php-fpm 

2.3.5 查询服务状态

ps-aux|grepphp-fpmnetstat-antp|grepphp-fpm

2.3.6 手动关闭服务

kill-s15`pgrep-urootphp-fpm`

2.4 配置服务启动

2.4.1 配置启动脚本

vim/usr/lib/systemd/system/php-fpm.service

加入如下配置:

[Unit]Description=ThePHPFastCGIProcessManagerAfter=syslog.targetnetwork.target[Service]Type=simplePIDFile=/run/php-fpm/php-fpm.pidEnvironmentFile=/etc/sysconfig/php-fpmExecStart=/usr/sbin/php-fpm--nodaemonizeExecReload=/bin/kill-USR2$MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target

配置环境文件:

echo #Additionalenvironmentfileforphp-fpm  /etc/sysconfig/php-fpm

重载控制脚本

systemctldaemon-reload

2.4.2 启动服务并配置默认启动

systemctlstartphp-fpmsystemctlenablephp-fpm

2.4.3 服务其他控制命令

systemctlstartphp-fpmsystemctlrestartphp-fpmsystemctlstopphp-fpm

2.5 测试

由于nginx不是本章的重点,所以如需测试请根据以下文章配置nginx,

http://blog.51cto.com/cmdschool/1962061

最后你可以看到如下页面,

参阅文档:

==============================================

http://sg2.php.net/manual/en/install.unix.nginx.php

版权声明:原创作品,谢绝转载。否则将追究法律责任 php php 往往为了自己的不能失败,而处心积虑前怕狼后怕虎,

如何最接近rpm的安装方式去编译安装最新的php-fpm推荐

相关文章:

你感兴趣的文章:

标签云: