【基本解决】CentOS 7中查看PHP运行时的Log文件日志信息

前端之家收集整理的这篇文章主要介绍了【基本解决】CentOS 7中查看PHP运行时的Log文件日志信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

【背景】

折腾:

【已解决】PHP代码尝试使用vsprintf期间出错无任何输出

期间,需要搞懂,对于服务器上面运行的PHP代码,期间的log输出到哪里。

想要去查看对应的log,找到代码无法运行的原因。

【折腾过程】

1.搜:

check PHP log

centos check PHP log

参考:

Where does PHP store the error log? – Stack Overflow

apache2 – Where are the Apache and PHP log files? – Ask Ubuntu

去看看:

自己此处的/var/log/下面没有apache2或apache

2.通过:

PHPinfo()

去找error_log

结果得到:

error_log

no value

no value

3.所以去设置PHP.ini的log日志:

【已解决】CentOS 7中PHP配置文件php.ini的放在哪个位置

4.然后去编辑PHP.ini,添加对应的error_log

vi /etc/PHP.ini

把:

?
1
2
3
4
5
6
7
; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; Example:
;error_log = PHP_errors.log
; Log errors to syslog (Event Log on NT,not valid in Windows 95).
;error_log = syslog

改为:

error_log = /var/log/PHP_errors.log
;error_log = syslog

5.同时把:

?
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@H_502_193@ 24
25
26
27
28
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
......
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
; E_DEPRECATED - warn about code that will not work in future versions
; of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
;
; Common Values:
; E_ALL (Show all errors,warnings and notices including coding standards.)
; E_ALL & ~E_NOTICE (Show all errors,except for notices)
; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors,except for notices and coding standards warnings.)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

改为:

?
2
#error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
error_reporting = E_ALL | E_STRICT

6.再去添加读写权限:

9
root@chantyou:log # pwd
/var/log
# touch /var/log/PHP_errors.log
# ls /var/log/PHP_errors.log -l
-rw-r--r-- 1 root root 0 Jul 28 16:03 /var/log/PHP_errors .log
# chmod +rw /var/log/PHP_errors.log
# ls /var/log/PHP_errors.log -l
.log
#

此处由于都是root用户,所以和没添加一样。。。

7.然后重启apache2:

?
24
# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
# service httpd status
status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded ( /usr/lib/systemd/system/httpd .service; disabled)
Active: active (running) since Tue 2015-07-28 16:05:13 CST; 7s ago
Process: 6858 ExecStop= /bin/kill -WINCH ${MAINPID} (code=exited,status=0 /SUCCESS )
Process: 2224 ExecReload= /usr/sbin/httpd $OPTIONS -k graceful (code=exited,255)!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; width:auto!important; min-height:auto!important; background:none!important">)
Main PID: 6864 (httpd)
Status: "Processing requests..."
CGroup: /system .slice /httpd .service
├─6864 -DFOREGROUND
├─6866 -DFOREGROUND
├─6867 -DFOREGROUND
├─6868 -DFOREGROUND
├─6869 -DFOREGROUND
└─6870 -DFOREGROUND
Jul 28 16:05:13 chantyou.com httpd[6864]: AH00548: NameVirtualHost has no effect and will be removed in the next release /e ...conf:1
Jul 28 16:05:13 chantyou.com httpd[6864]: AH00558: httpd: Could not reliably determine the server's fully qualified domain ...essage
Jul 28 16:05:13 chantyou.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized,use -l to show full.
#

8.看看有无log输出了:

# tail /var/log/PHP_errors.log
#

结果空的。

那就继续去测试其他PHP,如果出错了,希望此处可以看到错误的log日志。

9.然后,也确定了PHPinfo()中是可以看到有错误日志的配置了:

/var/log/PHP_errors.log

/var/log/PHP_errors.log

【总结】

暂时反正是设置了PHP错误日志,但是实际上后续的一些错误,比如代码的语法错误,结果却没有任何输出

感觉可能还是某些地方禁止错误输出

估计是那个:

display_errors

暂不确定。

暂不去深究了。

猜你在找的CentOS相关文章