沒有使用集成環(huán)境,從頭開始學(xué)習安裝配置PHP夯缺。
PHP-FPM配置
參數(shù) | 說明
-p | 命令行中動態(tài)修改--prefix
;include=etc/fpm.d/*.conf | 用于包含一個或多個文件休溶,如果glob(3)存在(glob()函數(shù)返回匹配指定模式的文件名或目錄)
全局配置
;pid = run/php-fpm.pid 設(shè)置pid文件的位置代赁,默認目錄路徑 /usr/local/php/var
;error_log = log/php-fpm.log 記錄錯誤日志的文件,默認目錄路徑 /usr/local/php/var
;syslog.facility = daemon 用于指定什么類型的程序日志消息邮偎。
;syslog.ident = php-fpm 用于FPM多實例甄別
;log_level = notice 記錄日志的等級管跺,默認notice义黎,可取值alert, error, warning, notice, debug
;emergency_restart_threshold = 0 如果子進程在這個時間段內(nèi)帶有IGSEGV或SIGBUS退出禾进,則重啟fpm,默認0表示關(guān)閉這個功能
;emergency_restart_interval = 0 設(shè)置時間間隔來決定服務(wù)的初始化時間(默認單位:s秒)廉涕,可選s秒泻云,m分,h時狐蜕,d天
;process_control_timeout = 0 子進程等待master進程對信號的回應(yīng)(默認單位:s秒)宠纯,可選s秒,m分层释,h時婆瓜,d天
; process.max = 128 控制最大進程數(shù),使用時需謹慎
; process.priority = -19 處理nice(2)的進程優(yōu)先級別-19(最高)到20(最低)
;rlimit_files = 1024 設(shè)置主進程文件描述符rlimit的數(shù)量
;rlimit_core = 0 設(shè)置主進程rlimit最大核數(shù)
;events.mechanism = epoll 使用處理event事件的機制
; - select (any POSIX os)
; - poll (any POSIX os)
; - epoll (linux >= 2.5.44)
; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll (Solaris >= 7)
; - port (Solaris >= 10)
;daemonize = yes 將fpm轉(zhuǎn)至后臺運行贡羔,如果設(shè)置為“no”廉白,那么fpm會運行在前臺
;systemd_interval = 10
進程池的定義
[www]
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
;prefix = /path/to/pools/$pool 如果沒有制定,將使用全局prefix替代
user = nobody 進程的發(fā)起用戶和用戶組乖寒,用戶user是必須設(shè)置猴蹂,group不是
group = nobody
listen = 127.0.0.1:9000 監(jiān)聽ip和端口
;listen.backlog = 65535 設(shè)置listen(2)函數(shù)backlog
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660
;listen.acl_users =
;listen.acl_groups =
;listen.allowed_clients = 127.0.0.1 允許FastCGI客戶端連接的IPv4地址,多個地址用','分隔楣嘁,為空則允許任何地址發(fā)來鏈接請求
; process.priority = -19
pm = dynamic 選擇進程池管理器如何控制子進程的數(shù)量
static: 對于子進程的開啟數(shù)路給定一個鎖定的值(pm.max_children)
dynamic: 子進程的數(shù)目為動態(tài)的磅轻,它的數(shù)目基于下面的指令的值(以下為dynamic適用參數(shù))
pm.max_children: 同一時刻能夠存貨的最大子進程的數(shù)量
pm.start_servers: 在啟動時啟動的子進程數(shù)量
pm.min_spare_servers: 處于空閑"idle"狀態(tài)的最小子進程珍逸,如果空閑進程數(shù)量小于這個值,那么相應(yīng)的子進程會被創(chuàng)建
pm.max_spare_servers: 最大空閑子進程數(shù)量聋溜,空閑子進程數(shù)量超過這個值谆膳,那么相應(yīng)的子進程會被殺掉。
ondemand: 在啟動時不會創(chuàng)建撮躁,只有當發(fā)起請求鏈接時才會創(chuàng)建(pm.max_children, pm.process_idle_timeout)
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_timeout = 10s; 空閑進程超時時間
;pm.max_requests = 500 在派生新的子進程前摹量,每一個子進程應(yīng)該處理的請求數(shù)目,在第三方庫中解決內(nèi)存溢出很有用馒胆,設(shè)置為0則不會限制
;pm.status_path = /status 配置一個URI缨称,以便查看fpm狀態(tài)頁
狀態(tài)頁描述:
accepted conn: 該進程池接受的請求數(shù)量
pool: 進程池的名字
process manager: 進程管理,就是配置中pm指令祝迂,可以選擇值static睦尽,dynamic,ondemand
idle processes: 空閑進程數(shù)量
active processes: 當前活躍的進程數(shù)量
total processes: 總的進程數(shù)量=idle+active
max children reached: 達到最大子進程的次數(shù)型雳,達到進程的限制当凡,當pm試圖開啟更多的子進程的時候(僅當pm工作在dynamic時)
;ping.path = /ping 該ping URI將會去調(diào)用fpm監(jiān)控頁面,如果這個沒有設(shè)置纠俭,那么不會有URI被做為ping頁
;ping.response = pong 用于定制平請求的響應(yīng)沿量,響應(yīng)的格式text/plain(對200響應(yīng)代碼)
;access.log = log/$pool.access.log
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
; The following syntax is allowed
; %%: the '%' character
; %C: %CPU used by the request
; it can accept the following format:
; - %{user}C for user CPU only
; - %{system}C for system CPU only
; - %{total}C for user + system CPU (default)
; %d: time taken to serve the request
; it can accept the following format:
; - %{seconds}d (default)
; - %{miliseconds}d
; - %{mili}d
; - %{microseconds}d
; - %{micro}d
; %e: an environment variable (same as $_ENV or $_SERVER)
; it must be associated with embraces to specify the name of the env
; variable. Some exemples:
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
; %f: script filename
; %l: content-length of the request (for POST request only)
; %m: request method
; %M: peak of memory allocated by PHP
; it can accept the following format:
; - %{bytes}M (default)
; - %{kilobytes}M
; - %{kilo}M
; - %{megabytes}M
; - %{mega}M
; %n: pool name
; %o: output header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
; - %{Transfert-Encoding}o
; - ....
; %p: PID of the child that serviced the request
; %P: PID of the parent of the child that serviced the request
; %q: the query string
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
; %s: status (response code)
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; %u: remote user
;slowlog = log/$pool.log.slow 用于記錄慢請求
;request_slowlog_timeout = 0 慢日志請求超時時間,對一個php程序進行跟蹤冤荆。
;request_terminate_timeout = 0 終止請求超時時間朴则,在worker進程被殺掉之后,提供單個請求的超時間隔钓简。由于某種原因不停止腳本執(zhí)行時乌妒,應(yīng)該使用該選項,0表示關(guān)閉不啟用
(在php.ini中外邓,max_execution_time 一般設(shè)置為30撤蚊,表示每一個腳本的最大執(zhí)行時間)
;rlimit_files = 1024 設(shè)置打開文件描述符的限制
;rlimit_core = 0 設(shè)置內(nèi)核對資源的使用限制,用于內(nèi)核轉(zhuǎn)儲
;chroot = 設(shè)置chroot路徑损话,程序一啟動就將其chroot放置到指定的目錄下侦啸,該指令值必須是一個絕對路徑
;chdir = /var/www 在程序啟動時將會改變到指定的位置(這個是相對路徑,相對當前路徑或chroot后的“/”目錄)
;catch_workers_output = yes 將worker的標準輸出和錯誤輸出重定向到主要的錯誤日志記錄中丧枪,如果沒有設(shè)置光涂,根據(jù)FastCGI的指定,將會被重定向到/dev/null上
;clear_env = no 清理環(huán)境
;security.limit_extensions = .php .php3 .php4 .php5 限制FPM執(zhí)行解析的擴展名
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
; 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
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M