php-fpm包的安裝與配置


實驗環境:CentOS7

[root@~ localhost]#yum -y install php-fpm
php-fpm包:用於將php運行於fpm模式
#在安裝php-fpm時,一般同時安裝如下包
[root@~ localhost]#yum -y install php-mbstring php-mcrypt php-mysql
[root@~ localhost]#rpm -ql php-fpm
/etc/logrotate.d/php-fpm    
/etc/php-fpm.conf    #服務配置文件 /etc/php-fpm.d /etc/php-fpm.d/www.conf #主配置文件
/etc/sysconfig/php-fpm
/run/php-fpm
/usr/lib/systemd/system/php-fpm.service
/usr/lib/tmpfiles.d/php-fpm.conf
/usr/sbin/php-fpm
/usr/share/doc/php-fpm-5.4.16
/usr/share/doc/php-fpm-5.4.16/fpm_LICENSE
/usr/share/doc/php-fpm-5.4.16/php-fpm.conf.default
/usr/share/fpm
/usr/share/fpm/status.html    #內置的網頁狀態測試頁面 /usr/share/man/man8/php-fpm.8.gz
/var/log/php-fpm
[root@~ localhost]#vi /etc/php-fpm.conf 

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;
; Global Options ;  #全局配置選項
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Default Value: none
pid = /run/php-fpm/php-fpm.pid    #內存中的進程編號文件

; Error log file
; Default Value: /var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log    #錯誤日志文件

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice              #定義日志級別

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
daemonize = no          #是否以守護進程的方式運行,no表示不是 
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;        #定義連接池,對應的文件是:/etc/php.-fpm.d/www.conf
;;;;;;;;;;;;;;;;;;;;

; See /etc/php-fpm.d/*.conf
    

 

#fpm模式監聽的端口是9000
[root@php-fpm.d localhost]#cp -av www.conf{,.bak} #修改配置文件時先備份 ‘www.conf’ -> ‘www.conf.bak’ [root@php-fpm.d localhost]#vi www.conf ; Start a new pool named 'www'. [www] ; Note: This value is mandatory. listen = 127.0.0.1:9000    #監聽本地的ip和端口; ; Set listen(2) backlog. A value of '-1' means unlimited. ; Default Value: -1

;listen.backlog = -1      #后援隊列:當請求數大於並發數時,設置排隊等待的請求數;-1表示無限制

listen.allowed_clients = 127.0.0.1  #授權設置,允許那些主機可以連接本服務主機;若httpd在別的主機,則需要修改

user = apache        #運行進程的用戶
; RPM: Keep a group allowed to write in log dir.
group = apache        #運行進程的組 

#運行子進程的方式:static 靜態方式 和dynamic 動態方式

; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives:
; pm.max_children - the maximum number of children that can
; number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic  #以動態方式運行

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either 'static' or 'dynamic'
; Note: This value is mandatory.
pm.max_children = 50    #最大子進程數

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 5    #服務啟動,先創建的服務數量

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 5  #啟動的最小空閑服務數量,應大於啟動時創建的服務數

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35  #啟動的最大空閑服務數量

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 500  #每個子進程最多響應多少個請求,然后關閉

; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. By default, the status page shows the following
; information:
; accepted conn - the number of request accepted by the pool;
; pool - the name of the pool;
; may conflict with a real PHP file.
; Default Value: not set
pm.status_path = /pmstatus  #啟用此行,內置狀態頁,改成pmstatus

; may conflict with a real PHP file.
; Default Value: not set
ping.path = /ping    #服務器遠程健康狀況探測,檢測服務器是否正常

; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
ping.response = pong  #探測回應

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0  #響應超時時間,0表示不超時

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)

; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; exectute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5

 

; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can

pm.min_spare_servers = 5

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 500

php_value[session.save_handler] = files

php_value[session.save_path] = /var/lib/php/session  

#服務器端保存的會話的路徑,默認沒有創建,需手動創建,並將屬主和屬組修改修改成此進程的屬主和屬組,即apache:apache

"www.conf" 226L, 10018C       

 

[root@php-fpm.d localhost]#mkdir -pv /var/lib/php/session  #創建會話的文件
[root@php-fpm.d localhost]#chown apache:apache /var/lib/php/session  #修改文件的屬組屬組為apache:apache
[root@php-fpm.d localhost]#systemctl start php-fpm.service  #啟動php-fpm服務
[root@php-fpm.d localhost]#ss -ntl |grep "9000"        #檢查9000端口是否啟動
LISTEN     0      128    127.0.0.1:9000                     *:* 
[root@php-fpm.d localhost]#ps aux | grep "php-fpm"      #檢查主進程和子進程是否按照配置生成
root      43438  0.8  1.1 330704 10440 ?        Ss   13:05   0:00 php-fpm: master process (/etc/php-fpm.conf)
apache    43440  0.0  0.5 332788  5060 ?        S    13:05   0:00 php-fpm: pool www
apache    43441  0.0  0.5 332788  5060 ?        S    13:05   0:00 php-fpm: pool www
apache    43442  0.0  0.5 332788  5060 ?        S    13:05   0:00 php-fpm: pool www
apache    43443  0.0  0.5 332788  5060 ?        S    13:05   0:00 php-fpm: pool www
apache    43444  0.0  0.5 332788  5060 ?        S    13:05   0:00 php-fpm: pool www
root      43465  0.0  0.1 112648   964 pts/5    S+   13:07   0:00 grep --color=auto php-fpm

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM