主配置文件:/usr/local/php-fpm/etc/php-fpm.conf #include=/usr/local/php-fpm/etc/php-fpm.d/*.conf
实际生效子配置文件:/usr/local/php-fpm/etc/php-fpm.d/www.conf
user = php-fpm
group = php-fpm
listen.group = php-fpm
listen.owner = php-fpm
listen.allowed_clients = 127.0.0.1
定义允许访问的客户端,一般情况保持默认pool 名字:[www] 可以自定义,启动后,ps aux |grep php-fpm 看最右侧,就是pool的名字
[root@feature1 etc]# ps aux |grep php-fpm
root 7286 0.0 0.3 230484 6444 ? Ss 09:22 0:01 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 7287 0.0 0.4 230920 9276 ? S 09:22 0:00 php-fpm: pool bbs
php-fpm 7288 0.0 0.4 230920 9216 ? S 09:22 0:00 php-fpm: pool bbs
php-fpm 7289 0.0 1.1 315020 22780 ? S 09:22 0:00 php-fpm: pool blog
php-fpm 7290 0.0 0.3 230476 6364 ? S 09:22 0:00 php-fpm: pool blog
root 7382 0.0 0.0 112724 984 pts/1 S+ 10:10 0:00 grep --color=auto php-fpm
listen 指定监听的IP:port或者socket地址。这个地址需要和nginx配置文件里面的fastcgi_pass所配置的地址一致,否则就会502错误。如果监听的是socket文件,nginx配置文件修改成(fastcgi_pass unix:/tmp/www.socket;)并且要保证nginx服务用户(nginx)对该socket文件有读写权限,否则也会报502错误。修改完监听权限需要重启php-fpm服务,重新生成socket文件。
listen = 127.0.0.1:9000
listen = /tmp/www.socket
listen.mode 指定socket文件的权限
listen.mode = 0660 #一般修改成0666
pm = dynamic #动态模式
pm.max_children = 5 #最大进程数
pm.start_servers = 2 #启动几个子进程
pm.min_spare_servers = 1 #空闲时,最少不能少于几个子进程
pm.max_spare_servers = 3 #空闲时,最多不能多于几个子进程
pm.max_requests = 500 #单个子进程最多处理多少个请求
php_flag[display_errors] = off
生产环境一般保持off,排错调试可临时打开,错误信息会显示在网页上 php_admin_value[error_log] = /var/log/fpm-php.www.log php_admin_flag[log_errors] = on php_admin_value[error_reporting] = E_ALL #错误日志级别 [root@linux2019 conf.d]# /usr/local/php-fpm/sbin/php-fpm -t #检查配置是否正确 [root@linux2019 conf.d]# /etc/init.d/php-fpm reload #重载配置文件 1 2 查看php.ini文件路径(phpinfo)
#php -i 执行该命令会调用phpinfo()函数
[root@feature1 etc]# /usr/local/php-fpm/bin/php -i |head
phpinfo()
PHP Version => 7.3.1
System => Linux linux2019 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:43 UTC 2018 x86_64
Build Date => Jan 23 2019 11:05:01
Configure Command => './configure' '--prefix=/usr/local/php-fpm' '--with-config-file-path=/usr/local/php-fpm/etc' '--enable-fpm' '--with-fpm-user=php-fpm' '--with-fpm-group=php-fpm' '--with-mysql=/usr/local/mysql5.6' '--with-mysqli=/usr/local/mysql5.6/bin/mysql_config' '--with-pdo-mysql=/usr/local/mysql5.6' '--with-mysql-sock=/tmp/mysql.sock' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-zlib-dir' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-ftp' '--enable-mbstring' '--enable-exif' '--with-pear' '--with-curl' '--with-openssl'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/php-fpm/etc
Loaded Configuration File => /usr/local/php-fpm/etc/php.ini
[root@feature1 bbs.feature.com]# vim phpinfo.php
phpinfo()
?>
[root@feature1 bbs.feature.com]# chmod 777 phpinfo.php
[root@feature1 bbs.feature.com]# curl -k https://bbs.feature.com/phpinfo.php
#查看php基本配置信息
[root@feature1 etc]# vi /usr/local/php-fpm/etc/php.ini
#关闭phpinfo函数功能
disable_functions = phpinfo
[root@feature1 etc]# curl -k -H "host:bbs.feature.com" https://127.0.0.1/phpinfo.php -I
#但是一般情况下不建议开启phpinfo函数功能,且不建议在根目录创建此文件,存在安全隐患!
配置slow日志
在排查网页加载缓慢的情况,可以通过slowlog日志查看、优化
slowlog = /var/log/www.log.slow
request_slowlog_timeout = 1
#脚本执行超时时间,执行超时的文件详情将被记入在日志中
配置open_basedir
定义php服务能够活动的目录范围
vi /usr/local/php-fpm/etc/php.ini open_basedir = /data/wwwroot/bbs.aibenwoniu.xyz:/tmp #目录之间以:分割,/tmp目录一般会成一切临时文件,如日志文件、socket之类的 存在问题:如果bbs网站安全泄露,存在同一个路径的blog网站也存在泄露的风险 解决方案:为blog网站新建一个blog.conf文件,用不同的pool控制管理,注意新建的pool中listen参数要区分开(端口或者socket)
[root@feature1 php-fpm.d]# vim blog.conf
[blog]
user = php-fpm
group = php-fpm
listen = /tmp/blog.socket
listen.mode = 0666
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
slowlog = /var/log/$pool.log.slow
request_slowlog_timeout = 1
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.blog.log
php_admin_flag[log_errors] = on
php_admin_value[error_reporting] = E_ALL
php_admin_value[open_basedir] = /data/wwwroot/blog.feature.com:/tmp
[root@feature1 php-fpm.d] grep -v ^\; bbs.conf |grep -v ^$
[bbs]
user = php-fpm
group = php-fpm
listen = 127.0.0.1:9000
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
slowlog = /var/log/$pool.log.slow
request_slowlog_timeout = 1
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.bbs.log
php_admin_flag[log_errors] = on
php_admin_value[error_reporting] = E_ALL
php_admin_value[open_basedir] = /data/wwwroot/bbs.feature.com:/tmp
备注:php-fpm配置文件中两类参数格式
php_flag #on/off
php_admin_value
#配置具体参数
!