php:配置php-fpm(PHP 8.2.5)

一,创建php日志的存放目录:

[root@img etc]# mkdir /web/logs/phplogs
[root@img etc]# chmod 777 /web/logs/phplogs/

二,配置php-fpm

编辑配置文件的命令:
root@img ~]# cd /usr/local/soft/php8.2.5/etc/
[root@img etc]# cd php-fpm.d/
[root@img php-fpm.d]# vi www.conf
1,指定用户:修改为和nginx一致的nginx用户,
而不是使用默认的nobody用户
;user = nobody
;group = nobody
user = nginx
group = nginx
2,配置pm
max_children默认值5,一般按一个进程30M内存占用计算,用总内存/30M,
假设供php使用内存为3G,此处我们设置为100
;pm.max_children = 5
pm.max_children = 100

start_servers的取值:建议取业务运行时php进程的平均数

注意注释中三者的关系:
start_servers: Default Value: (min_spare_servers + max_spare_servers) / 2
; 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) / 2
; pm.start_servers = 2
pm.start_servers = 4


; 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 = 1
pm.min_spare_servers = 2


; 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 = 3
pm.max_spare_servers = 6
3,配置慢查询日志:
指定慢查询的日志路径
slowlog = /web/logs/phplogs/php7-fpm_slow.log
超过指定秒数的查询被视为慢查询
request_slowlog_timeout = 2

三,配置完成后,要重新启动php-fpm服务

[root@img php-fpm.d]# systemctl restart php-fpm.service

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/06/php-pei-zhi-phpfpm-php-8-2-5/

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

四,查看php的版本:

[root@img daemon]# /usr/local/soft/php8.2.5/bin/php --version
PHP 8.2.5 (cli) (built: May 10 2023 14:51:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies

 

posted @ 2023-05-11 15:23  刘宏缔的架构森林  阅读(996)  评论(0编辑  收藏  举报