一,php錯誤與日誌的配置
1,建立php的日誌保存目錄:php
[root@yjweb ~]# mkdir -p /data/logs/phplogs [root@yjweb ~]# chmod 777 /data/logs/phplogs
2,編輯php.ini中指定錯誤相關的信息:linux
[root@yjweb ~]# vi /usr/local/soft/php7/etc/php.ini
配置內容爲: nginx
1,確認log_errors的值是On,git
其默認值是On,通常不須要修改github
log_errors = On
2,確保display_errors的值是Off,web
其默認值是Off,通常不須要修改centos
說明:在線上不能直接在頁面上顯示報錯信息,會把目錄結構/數據表/等暴露出去session
display_errors = Off
3,重點:指定error_log的值,php7
error_log = /data/logs/phplogs/php7_errors.log
說明:默認的錯誤日誌寫到這裏架構
說明:劉宏締的架構森林是一個專一架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼能夠訪問這裏獲取: https://github.com/liuhongdi/
說明:做者:劉宏締 郵箱: 371125307@qq.com
二,php.ini中須要手動配置的項目:
須要手動指定的環節:
1,時區:
date.timezone = Asia/Shanghai
2,單次post的最大數據量:
post_max_size = 128M
3,文件上傳時文件大小限制:
upload_max_filesize = 64M
4,腳本可以使用的最大內存大小
memory_limit = 128M
5,每一個腳本用來解析請求數據的最長的時間
默認60s
max_input_time = 60
6,session的生命週期,設置爲1個小時
session.gc_maxlifetime = 3600
三,建立運行php的nginx用戶
[root@yjweb ~]# groupadd nginx [root@yjweb ~]# useradd nginx -g nginx -s /sbin/nologin -M [root@yjweb ~]# grep nginx /etc/passwd nginx:x:1001:1001::/home/nginx:/sbin/nologin
說明:php-fpm的默認運行用戶是nobody,
它是一個linux系統的內置用戶,
若是有須要統一uid的地方則不方便去修改它,
因此咱們自建一個nginx帳戶,用來運行nginx和php-fpm
四,php-fpm的設置之php-fpm.conf
1,配置php-fpm.conf
[root@yjweb ~]# vi /usr/local/soft/php7/etc/php-fpm.conf
配置內容爲:
指定php-fpm的錯誤日誌
error_log = /data/logs/phplogs/php-fpm_error.log
五,php-fpm的設置之配置www.conf
[root@yjweb ~]# vi /usr/local/soft/php7/etc/php-fpm.d/www.conf
配置內容爲:
1,配置用戶和組,使用本身創建的nginx用戶
user = nginx group = nginx
2,配置pm
pm.max_children = 128 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 35
說明:依次爲:最大子進程數量
最小子進程數量:即:啓動時的數量
最小閒置子進程數量
最大閒置子進程數量:閒置的子進程數量超出此數字的會被殺掉
3,配置慢查詢
slowlog = /data/logs/phplogs/php-fpm_slow.log request_slowlog_timeout = 2s
說明:配置2s超時
六,查看本地centos的版本
[webop@yjweb ~]$ cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)
七,查看本地php的版本
[root@yjweb etc]# /usr/local/soft/php7/bin/php -v PHP 7.4.2 (cli) (built: Mar 5 2020 11:16:38) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies
八,使systemctl支持php的服務
1,新增service文件
[root@localhost daemon]# vi /usr/lib/systemd/system/php-fpm.service [root@localhost daemon]# systemctl daemon-reload [root@localhost daemon]# systemctl start php-fpm [root@localhost daemon]# systemctl stop php-fpm
2,service文件的內容:
[Unit] Description=php-fpm After=network.target [Service] Type=forking ExecStart=/usr/local/soft/php7/daemon/php-fpm start ExecStop=/usr/local/soft/php7/daemon/php-fpm stop PrivateTmp=true [Install] WantedBy=multi-user.target