003_PHP configuration

PHP configuration

1. php-fpm of pool

1.1 open pool configuration

#### 编辑 php-fpm 配置文件 php-fpm.con
vim /usr/local/php/etc/php-fpm.conf
#### 在[global]部分增加以下内容
include = etc/php-fpm.d/*.conf  # 相当与Nginx的虚拟主机文件 “vhost” 的配置
#### 创建存放pool配置文件目录
mkdir /usr/local/php/etc/php-fpm.d/
cd /usr/local/php/etc/php-fpm.d/

1.2 Creating a pool configuration file www

vim www.conf
#### 内容如下
[test]
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

1.3 Creating a pool configuration file test2

vim test2.conf
#### 内容如下
[admin]
listen = /tmp/test2.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

/usr/local/php/sbin/php-fpm –t

/etc/init.d/php-fpm restart

2. php-fpm slow execution log

2.1 Turning slow log configuration

#### 编辑php-fpm的pool文件;
vim /usr/local/php-fpm/etc/php-fpm.d/test2.conf
#### 添加慢日志记录配置
request_slowlog_timeout = 1
# 超过1秒的php解析 记录一次慢日志,实际生产环境中 设置2秒
slowlog = /usr/local/php-fpm/var/log/test2-slow.log
# 慢日志存放路径、名称

2.2 Test slow log configuration

Virtual Host Configuration test2.com.conf nginx, and the unix: /tmp/php-fcgi.sock read unix: /tmp/test2.sock

Reload nginx service

#### 创建测试html页面
vim /data/wwwroot/test2.com/sleep.php
#### 内容如下
<?php
echo "test slow log";
sleep(2);
echo "done";
?>

curl -x127.0.0.1:80 test2.com/sleep.php

cat /usr/local/php-fpm/var/log/test2-slow.log

3. php-fpm defined open_basedir

3.1 open open_basedir configuration

open_basedir restriction directory php parsed

LAMP architecture open_basedir can also be set in the Apache configuration; LNMP architecture settings directly in the settings file in php

vim /usr/local/php-fpm/etc/php-fpm.d/admin.conf
#### 配置文件中加入如下内容
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
# 这里限制的目录为“/data/wwwroot/test.com”/和“/tmp/”目录

Create the test php scripts for testing; change again test.conf, modify open_basedir path, test again, the configuration error log, test again to see the error log

Error Log 3.2 php-fpm configuration

Edit the configuration file:

vim /opt/php-fpm/etc/php.ini
……
display_errors = Off
;错误显示 “Off 关闭” “On 开启” ,开启后会在浏览器中显示错误信息;生产环境不开启
……
error_log = error_log = /opt/php-fpm/var/log/error.log
;定义日志位置、日志名称
……
error_reporting = E_ALL
;定义日志级别
……

Create a log file

#### 创建错误日志文件
touch  /opt/php-fpm/var/log/error.log
#### 设置权限777 (创建日志文件,设置权限,防止因权限问题导致日志无法记录)
chmod 777 /opt/php-fpm/var/log/error.log

4. php-fpm Process Management

Parameter Description section profile php-fpm.conf

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的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出。

Guess you like

Origin www.cnblogs.com/cy-8593/p/12333617.html