php.ini 配置错误
我已经缩小了我的问题范围。 当我从命令行运行 "error_log('hey');"
时,它会转储到 STDOUT。但是,如果我从 Web 界面 (Apache) 运行相同的代码,它会将错误放入错误日志中。 我检查了两个 ini 文件,一个是 Apache 正在使用的文件,另一个是 /private/etc 中的文件(我在一台运行 MAMP 的 Mac 上)。两个 error_log 变量都指向完全相同的位置。 当我运行时,
echo ini_get('error_log');
命令行上的值与浏览器中的值相同。 这里什么ini设置配置错误?这非常烦人,因为不仅仅是错误日志记录被破坏了。它也影响我的包含路径:/
I've narrowed my problem down somewhat.
When I run "error_log('hey');"
from the command line it dumps to STDOUT. But if I run the same code from my web interface (Apache) it puts the error in the error log.
I've checked both ini files, the one Apache is using, and the one in /private/etc (I'm on a Mac running MAMP). Both error_log variables point to the exact same place.
And when I run
echo ini_get('error_log');
The value is the same on the command line as it is in the browser.
What ini setting is misconfigured here? This is quite annoying, as more than just error logging is broken. It's affecting my include paths as well :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你想实现什么目标?在 apache 中,stderr 进入
error_log
...error_log()
功能文档指出,默认情况下它会记录到服务器的错误日志中。如果您想登录到不同的目标,请使用message_type
和destination
参数。What are you trying to accomplish? Within apache, stderr goes into the
error_log
... theerror_log()
function documentation states that by default it logs to the server's error log. If you want to log to a different destination, use themessage_type
anddestination
parameters.您可能需要编辑以下配置文件:
MAMP 使用它自己的 Apache 服务器,默认情况下在端口 8080 上运行。您可能想在系统偏好设置 -> 中关闭 Apache 服务器。分享。
另外,尝试运行包含以下内容的 PHP 文件:
这将告诉您 Apache 实际上正在读取哪个 php.ini。
将要
You probably need to edit the following config file:
MAMP uses it's own Apache server, which by default runs on port 8080. You probably want to turn off the Apache server in the System Preferences -> Sharing.
Also, try running a PHP file containing:
This will tell you which php.ini is actually being read by Apache.
Will
error_log 显示在控制台中而不是日志文件中的原因可能是由于权限问题 - 我不太了解 MacOS,但由于它是基于 UNIX 的,我猜测:
如果它无法记录到日志文件,我认为 error_log 是写入错误的标准输出(stderr),通常是控制台。
手册页面上的此评论似乎表明了这一点可能是您的问题的原因(引用):
另外,请确保
log_errors
< /a> 和display_errors
在 CLI 中使用的 php.ini 文件中正确配置:和 :
A reason for error_log displaying in the console, and not in the log file might be because of a problem with permissions -- I don't really know MacOS, but as it's UNIX-based, I'm guessing that :
If it can't log to the log file, I suppose that error_log is writting to the standard output for error (stderr), which is generally the console.
This comment on the manual's page seems to indicate this might be the cause of your problems (quoting) :
Also, make sure the
log_errors
anddisplay_errors
are properly configured in the php.ini file used in CLI :And :
这里相关的ini设置是
display_errors
。在命令行中,
On
值会将错误转储到STDOUT
;stderr
会将它们转移到 STDERR,而Off
将抑制它们。对于 Apache,只有On
和Off
才有意义。很可能 Apache 的 ini 文件具有
display_errors = Off
,而 /private/etc 中的 ini 文件具有display_errors = On
。error_log
指令告诉 PHP 将错误记录到何处,但它也要求将log_errors
设置为On
,否则无效。 (同样,/private/etc 中的 ini 文件可能有log_errors = Off
。)The relevant ini setting here is
display_errors
.From the command line a value of
On
will dump the errors toSTDOUT
;stderr
will divert them to STDERR andOff
will suppress them. For Apache onlyOn
andOff
make any sense.The odds are that the ini file for Apache has
display_errors = Off
whilst the one in /private/etc hasdisplay_errors = On
.The
error_log
directive tells PHP where to log errors to, but it also requireslog_errors
to be set toOn
, otherwise it has no effect. (Again, chances are the ini file in /private/etc haslog_errors = Off
.)