[LNMP]php-fpm相關配置
php-fpm pool
方式一
1、編輯php-fpm配置檔案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
[root@plinuxos ~] # vi /usr/local/php-fpm/etc/php-fpm.conf
[global] pid = /usr/local/php-fpm/var/run/php-fpm .pid
error_log = /usr/local/php-fpm/var/log/php-fpm .log
[www] listen = /tmp/php-fcgi .sock
listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 #####新增以下內容##### [ test .com]
listen = /tmp/test .sock
listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 |
2、檢查與過載
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
[root@plinuxos ~] # /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2017 21:15:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm .conf test is successful
[root@plinuxos ~] # /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@plinuxos ~] # ps aux |grep php-fpm
root 88331 0.0 0.1 226756 4976 ? Ss 21:15 0:00 php-fpm: master process ( /usr/local/php-fpm/etc/php-fpm .conf)
php-fpm 88332 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88333 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88334 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88335 0.0 0.1 226696 4712 ? S 21:15 0:00 php-fpm: pool www php-fpm 88336 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88337 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88338 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88339 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88340 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88341 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88342 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool www php-fpm 88343 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88344 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88345 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88346 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88347 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88348 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88349 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88350 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88351 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool www php-fpm 88352 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88353 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88354 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88355 0.0 0.1 226696 4716 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88356 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88357 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88358 0.0 0.1 226696 4720 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88359 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88360 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88361 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88362 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88363 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88364 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88365 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88366 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88367 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88368 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88369 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88370 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
php-fpm 88371 0.0 0.1 226696 4724 ? S 21:15 0:00 php-fpm: pool test .com
root 88492 0.0 0.0 112652 968 pts /0 S+ 21:16 0:00 grep --color=auto php-fpm
|
3、編輯網站配置檔案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@plinuxos ~] # vi /usr/local/nginx/conf/vhost/default.conf
server { listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default ;
access_log /tmp/default .log juispan;
location ~ .php$
{
include fastcgi_params;
fastcgi_pass unix: /tmp/test .sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default $fastcgi_script_name;
}
} |
方式二
1、編輯php-fpm配置檔案
1
2
3
4
5
|
[root@plinuxos ~] # vi /usr/local/php-fpm/etc/php-fpm.conf
[global] pid = /usr/local/php-fpm/var/run/php-fpm .pid
error_log = /usr/local/php-fpm/var/log/php-fpm .log
include=etc /php-fpm .d/*.conf
|
2、編輯網站配置檔案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
[root@plinuxos ~] # mkdir /usr/local/php-fpm/etc/php-fpm.d
[root@plinuxos ~] # vi /usr/local/php-fpm/etc/php-fpm.d/test.conf
[ test ]
listen = /tmp/test .sock
#listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [root@plinuxos ~] # vi /usr/local/php-fpm/etc/php-fpm.d/abc.conf
[www] listen = /tmp/php-fcgi .sock
#listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 |
3、檢查與過載
1
2
3
4
5
|
[root@plinuxos ~] # /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2017 21:15:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm .conf test is successful
[root@plinuxos ~] # /etc/init.d/php-fpm reload
Reload service php-fpm done
|
4、檢查效果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
[root@plinuxos ~] # ps aux |grep php-fpm
root 91955 0.1 0.1 226784 4980 ? Ss 21:50 0:00 php-fpm: master process ( /usr/local/php-fpm/etc/php-fpm .conf)
php-fpm 91956 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91957 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91958 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91959 0.0 0.1 226724 4728 ? S 21:50 0:00 php-fpm: pool www php-fpm 91960 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91961 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91962 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91963 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91964 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91965 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool www php-fpm 91966 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91967 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91968 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91969 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91970 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91971 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91972 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91973 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91974 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91975 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool www php-fpm 91976 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91977 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91978 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91979 0.0 0.1 226724 4732 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91980 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91981 0.0 0.1 226724 4736 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91982 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91983 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91984 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91985 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91986 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91987 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91988 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91989 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91990 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91991 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91992 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91993 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91994 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
php-fpm 91995 0.0 0.1 226724 4740 ? S 21:50 0:00 php-fpm: pool test
root 92012 0.0 0.0 112652 968 pts /0 S+ 21:50 0:00 grep --color=auto php-fpm
|
慢執行日誌
1、編輯網站配置檔案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@plinuxos ~] # vi /usr/local/php-fpm/etc/php-fpm.d/test.conf
[ test ]
listen = /tmp/test .sock
#listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 2 ##超過2秒記錄日誌
slowlog = /usr/local/php-fpm/var/log/test_slow .log
|
2、檢查與過載
1
2
3
4
5
6
|
[root@plinuxos ~] # /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2017 21:56:07] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm .conf test is successful
[root@plinuxos ~] # /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
|
3、檢查效果
1
2
3
4
5
|
[root@plinuxos ~] # cat /usr/local/php-fpm/var/log/test_slow.log
[17-Aug-2017 22:01:42] [pool test ] pid 92722
script_filename = /data/wwwroot/default/1 .php
[0x00007fc823e8f2d0] sleep () /data/wwwroot/default/1 .php:3
|
open_basedir
1、配置網站配置檔案
1
|
[root@plinuxos ~] # echo "php_admin_value[open_basedir]=/data/wwwroot/default:/tmp/" >> /usr/local/php-fpm/etc/php-fpm.d/test.conf ##限制default目錄下不可以訪問其他站點資源
|
2、編輯php.ini檔案
1
2
|
[root@plinuxos ~] # vi /usr/local/php-fpm/etc/php.ini
errot_log = /usr/local/php-fpm/var/log/php_error .log
|
3、檢查與過載
1
2
3
4
5
6
|
[root@plinuxos ~] # /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2017 21:15:03] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm .conf test is successful
[root@plinuxos ~] # /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
|
3、測試效果
1
2
3
4
5
6
|
[root@plinuxos ~] # touch /usr/local/php-fpm/var/log/php_error.log
[root@plinuxos ~] # chmod 777 /usr/local/php-fpm/var/log/php_error.log
[root@plinuxos ~] # curl -x127.0.0.1:80 abc.com/2.php
File not found. [root@plinuxos ~] # ls /data/wwwroot/abc.com/
2.php |
程式管理
▎配置檔案引數詳解:
pm = dynamic //動態程式管理,也可以是static
pm.max_children = 50 //最大子程式數,ps aux可以檢視
pm.start_servers = 20 //啟動服務時會啟動的程式數
pm.min_spare_servers = 5 //定義在空閒時段,子程式數的最少數量,如果達到這個數值時,php-fpm服務會自動派生新的子程式。
pm.max_spare_servers = 35 //定義在空閒時段,子程式數的最大值,如果高於這個數值就開始清理空閒的子程式。
pm.max_requests = 500 //定義一個子程式最多處理的請求數,也就是說在一個php-fpm的子程式最多可以處理這麼多請求,當達到這個數值時,它會自動退出。
本文轉自Grodd51CTO部落格,原文連結:http://blog.51cto.com/juispan/1957195,如需轉載請自行聯絡原作者
相關文章
- php-fpm相關配置PHP
- Spring配置相關Spring
- Git 相關配置Git
- JDBC 相關配置JDBC
- nginx配置相關Nginx
- VScode配置xdebug相關配置VSCode
- 關於lnmp配置laravel專案的問題?LNMPLaravel
- ubuntu中Django相關配置UbuntuDjango
- SpringCloud(1)-Eureka相關配置SpringGCCloud
- SpringCloud(3)-OpenFeign相關配置SpringGCCloud
- Mariadb之日誌相關配置
- Springmvc相關配置總結SpringMVC
- vue-router相關配置Vue
- PHP-FPM和nginx配置PHPNginx
- nginx + PHP-fpm 配置示例NginxPHP
- php-fpm 配置詳解PHP
- spring boot配置檔案相關Spring Boot
- mac iPhone郵箱相關配置MaciPhone
- 語義搜尋相關配置
- Spark的相關引數配置Spark
- 狀態列Theme相關配置
- keycloak~token配置相關說明
- ubuntu16 zabbix 相關配置Ubuntu
- dubbo相關配置以及注意項
- Linux-靜態路由相關配置Linux路由
- 高校郵件系統配置相關
- Git命令的使用和相關配置Git
- Eclipse中專案Maven相關配置EclipseMaven
- 4.2.10.1 Oracle Restart 相關變數配置OracleREST變數
- webpack4-05-配置vue相關WebVue
- linux系統相關概念與配置Linux
- SpringBoot資料來源相關配置Spring Boot
- php-fpm的配置和優化PHP優化
- 【Linux運維】LNMP環境配置Linux運維LNMP
- Location配置項及LNMP架構LNMP架構
- LNMP--mysql php安裝配置LNMPMySqlPHP
- mac下安裝nginx及相關配置MacNginx
- 一些Android Studio相關的配置Android
- docker 運用 gpu 網路相關配置DockerGPU