PHP

PHP 错误日志设置 - MAC

2020-04-26  本文已影响0人  887d1fc86fe6
; Besides displaying errors, PHP can also log errors to locations such as a
; server-specific log, STDERR, or a location specified by the error_log
; directive found below. While errors should not be displayed on productions
; servers they should still be monitored and logging is a great way to do that.
; Default Value: Off
; Development Value: On
; Production Value: On
; http://php.net/log-errors
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
error_log = ./error_log.txt

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <?php
  // 设置需要存放错误日志
  ini_set('log_errors', 'On');
  // 设置日志存放路径
  ini_set('error_log', './error_log.txt');

  // 错误的导入文件以及输出未定义的对象
  include 'lib/nav1.html';
  echo '<br>当前的页码为:' . $page;
  ?>
</body>
</html>

chmod -R 777 /Users/dengzemiao/Sites/dzm/php-1
或
sudo chmod -R 777 /Users/dengzemiao/Sites/dzm/php-1

打开权限之后,再次运行代码,应该就出来日志文件了

image.png

注意:我现在配置的日志目录是服务器根目录 /Users/dengzemiao/Sites 里面,但是我在桌面上随便创建一个文件夹并试图存放日志,也添加了权限,发现无效,所以建议放在配置的根目录里面设置打开权限。

上一篇 下一篇

猜你喜欢

热点阅读