做为一名程序员,比码代码还重要那么一点点的东西就是日志的分析和查询。下面列出常见日志及设置方法。php
php慢日志须要在php-fpm.conf设置,若是使用源码包安装默认请执行下面命令程序员
cp php-fpm.conf.default php-fpm.conf
默认经过源码包编译安装php目录应在vim
/usr/local/php
目录下,若是你经过yum或者其余方式安装,不清楚或不知道php具体安装目录,能够使用php7
find / -name php-fpm.conf
orphp-fpm
php -i | grep Path ------------------------------------------ [root@xxxx etc]# php -i | grep Path Configuration File (php.ini) Path => /usr/local/php/etc XPath Support => enabled Path to sendmail => /usr/sbin/sendmail -t -i [root@xxxx etc]#
旧的版本是在php-fpm.conf设置 (实际是我忘记了哪一个版本),php7.x版本源码包编译后须要www.conf修改慢查询配置this
vim /usr/local/php/etc/php-fpm.d/www.conf
不过配置项都同样的,若是你在php-fpm.conf找不到,就去他的同级目录php-fpm.d下面找下吧。spa
; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set ;slowlog = log/$pool.log.slow ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 ;request_slowlog_timeout = 0
在生产环境中是不容许php报错的,就算报错也是白屏或者500,因此在生产环境中的日志收集是很是重要的。.net
通常状况下,php错误日志的配置都在php.ini文件中日志
/usr/local/php/etc/php.ini --------------------------- error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors = Off log_errors = On ; Log errors to specified file. PHP's default behavior is to leave this value ; empty. ; http://php.net/error-log ; Example: ;error_log = php_errors.log ; Log errors to syslog (Event Log on Windows). ;error_log = syslog
最终的结果是code
error_log = /var/log/php_error.log display_errors = Off error_reporting = E_ALL log_errors = On
感谢你看到这里,日志操做与分析的相关文章后面我还会写一些,但愿能够帮助到你。谢谢
代码多变,初心不变