php-fpm配置详解

PHPFPM(FastCGI Process Manager)是一个PHP FastCGI实现,用于管理PHP进程,它可以在服务器上运行多个PHP进程,从而提高PHP应用程序的性能和稳定性,以下是PHPFPM配置的详细步骤:

php-fpm配置详解
(图片来源网络,侵删)

1、安装PHPFPM

在不同的操作系统上,安装PHPFPM的方法可能有所不同,以下是在一些常见操作系统上的安装方法:

Ubuntu/Debian:

sudo aptget update
sudo aptget install php7.4fpm

CentOS/RHEL:

sudo yum install epelrelease
sudo yum install php74wfpm

2、配置PHPFPM

配置文件位于/etc/php7.4/fpm/phpfpm.conf(根据实际安装的PHP版本进行修改),以下是一些常用配置项的解释:

配置项 默认值 描述
listen = /run/php/php7.4fpm.sock PHPFPM监听的套接字地址
listen = 127.0.0.1:9000 PHPFPM监听的IP地址和端口
user = nobody PHPFPM运行的用户
group = nobody PHPFPM运行的用户组
pm = dynamic PHPFPM进程管理方式,可选值为static(静态)或dynamic(动态)
pm.max_children = 5 PHPFPM启动时的初始进程数
pm.start_servers = 2 PHPFPM启动时创建的最小进程数
pm.min_spare_servers = 1 PHPFPM空闲进程的最小数量
pm.max_spare_servers = 3 PHPFPM空闲进程的最大数量
pm.max_requests = 500 每个子进程重生之前服务的请求数
request_terminate_timeout = 60s; 请求超时时间,超过此时间的请求将被终止并重启子进程
slowlog = /var/log/php7.4fpm/wwwslow.log 慢日志文件路径,记录执行时间超过设定阈值的请求信息
log_level = notice PHPFPM的日志级别,可选值为error、warning、notice、info、debug、trace
access_log = /var/log/php7.4fpm/access.log 访问日志文件路径,记录所有访问请求的信息
error_log = /var/log/php7.4fpm/error.log 错误日志文件路径,记录PHP错误信息
rlimit_files = 1024 单个进程允许打开的文件描述符数量上限
rlimit_core = unlimited 单个进程允许生成的核心转储文件大小上限
rlimit_memory = unlimited 单个进程允许使用的内存上限
rlimit_as = unlimited 单个进程允许打开的文件大小上限(包括管道)
chroot = /var/www/html PHPFPM的工作目录,即PHP应用程序所在的目录
chdir = /var/www/html PHPFPM的工作目录,即PHP应用程序所在的目录,与chroot选项二选一使用
catch_workers_output = yes 是否捕获子进程的标准输出和标准错误输出,可选值为yes或no
security.limit_extensions = .php .php3 .php4 .php5 .phtml .phps .phpt .phpdbg .phpdoc .pwd .sh .cgi .fcgi .py .pl .jsp .asp .htm .html .xml .xsl .css .js; 允许加载的PHP扩展名列表,多个扩展名用空格分隔
open_basedir = none /var/www/html:/tmp:/var/tmp:/usr/share/pear:/usr/share/webapps:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/httpd:/home/httpd/htdocs:/home/httpd/cgibin:/tmp:/var/tmp:/usr/share/pear:/usr/share/webapps:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/httpd:/home/httpd/htdocs:/home/httpd/cgibin; PHP脚本可以访问的文件和目录列表,多个路径用冒号分隔,开头为none表示禁用限制,建议设置为空字符串以启用限制功能

| disable_classes = "" | "ZendGuardLoader" "ZipArchive" "SPL" "SoapClient" "Phar" "SQLite3" "Composer" "Symfony" "DomCrawler" "ReactPromise" "amqplib" "phalconconsole" "phalcondi" "phalcondebug" "phalcondbadapter" "phalcondbdriverpostgresql" "phalcondbdriversqlite" "phalcondbprofiler" "phalcondevtools" "phalconevent" "phalconfilter" "phalconimage" "phalconimap" "phalconintegrationlibrary" "phalconinterceptors" "phalconmvcview" "phalconormmetadatareader" "phalconormquery" "phalconormschema" "phalconpaginator" "phalconrouter" "phalconsecurity" "phalconsession" "phalconstorageadapterfilesystem" "phalconstorageadaptermemory" "phalconstorageadaptermysql" "phalconstorageadapterpostgresql" "phalconstorageadapterredis" "phalconstorageadapter\stream" "phalcon\tag\ce" "phalcon\tagcfsg" "phalcon\tag\compiler" "phalcon\tag\cssdecoration" "phalcon\tag\cssoptimize" "phalcontag\decorator" "phalcon\tag\form" "phalcon\tag\jsconcat" "phalcon\tagjslayout" "phalcontag\jsrender" "phalcon\tag\less" "phalcon\tag\markdownmailer" "phalcon\tagmustachepartialscachebuster" "phalcon\tag

avigationmenu" "phalcon\tag\partialscachebuster" "phalcon\tag\robotstxt" "phalcon\tagsecurityheaders" "phalcontag\stylescombine" "phalcon\tag\tidyhtmlembeddedcssjs" "phalcon\view"; |禁用的PHP类名列表,多个类名用空格分隔,开头为空表示启用所有类名,建议设置为空字符串以启用所有类名,这里列出了一些常用的禁用类名示例,可以根据实际需求进行修改。

原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/679643.html

(0)
未希新媒体运营
上一篇 2024-06-10 04:08
下一篇 2024-06-10 04:14

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入