php.ini 配置错误

发布于 2024-08-03 16:21:45 字数 362 浏览 2 评论 0原文

我已经缩小了我的问题范围。 当我从命令行运行 "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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

久随 2024-08-10 16:21:45

你想实现什么目标?在 apache 中,stderr 进入 error_log...error_log() 功能文档指出,默认情况下它会记录到服务器的错误日志中。如果您想登录到不同的目标,请使用 message_typedestination 参数。

What are you trying to accomplish? Within apache, stderr goes into the error_log... the error_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 the message_type and destination parameters.

千里故人稀 2024-08-10 16:21:45

您可能需要编辑以下配置文件:

/Applications/MAMP/conf/php5/php.ini

MAMP 使用它自己的 Apache 服务器,默认情况下在端口 8080 上运行。您可能想在系统偏好设置 -> 中关闭 Apache 服务器。分享。

另外,尝试运行包含以下内容的 PHP 文件:

<?php phpinfo(); ?>

这将告诉您 Apache 实际上正在读取哪个 php.ini。

将要

You probably need to edit the following config file:

/Applications/MAMP/conf/php5/php.ini

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:

<?php phpinfo(); ?>

This will tell you which php.ini is actually being read by Apache.

Will

霓裳挽歌倾城醉 2024-08-10 16:21:45

error_log 显示在控制台中而不是日志文件中的原因可能是由于权限问题 - 我不太了解 MacOS,但由于它是基于 UNIX 的,我猜测:

  • 使用的日志文件Apache 属于特定用户
  • 当从控制台运行脚本时,您不是该用户,并且您没有对日志文件的写访问权限

如果它无法记录到日志文件,我认为 error_log 是写入错误的标准输出(stderr),通常是控制台。

手册页面上的此评论似乎表明了这一点可能是您的问题的原因(引用):

PHP 似乎会记录到 stderr,如果它
无法写入日志文件。命令
PHP 行回退到 stderr 因为
日志文件(通常)只是
可由网络服务器写入。

另外,请确保 log_errors< /a> 和 display_errors 在 CLI 中使用的 php.ini 文件中正确配置:

log_errors 布尔值

告诉脚本是否有错误消息
应该记录到服务器的错误
日志或错误日志。因此这个选项是
特定于服务器。

和 :

display_errors 字符串

这决定了错误是否应该
作为一部分打印到屏幕上
输出或者是否应该隐藏它们
来自用户。

值“stderr”将错误发送到
stderr 而不是 stdout。

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 :

  • The log file used by Apache belongs to a specific user
  • When running the script from the console, you are not that user, and you don't have write-access to the log file

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) :

it seems that PHP logs to stderr if it
can't write to the log file. Command
line PHP falls back to stderr because
the log file is (usually) only
writable by the webserver.

Also, make sure the log_errors and display_errors are properly configured in the php.ini file used in CLI :

log_errors boolean

Tells whether script error messages
should be logged to the server's error
log or error_log. This option is thus
server-specific.

And :

display_errors string

This determines whether errors should
be printed to the screen as part of
the output or if they should be hidden
from the user.

Value "stderr" sends the errors to
stderr instead of stdout.

帝王念 2024-08-10 16:21:45

这里相关的ini设置是 display_errors

在命令行中,On 值会将错误转储到 STDOUTstderr 会将它们转移到 STDERR,而 Off 将抑制它们。对于 Apache,只有 OnOff 才有意义。

很可能 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 to STDOUT; stderr will divert them to STDERR and Off will suppress them. For Apache only On and Off make any sense.

The odds are that the ini file for Apache has display_errors = Off whilst the one in /private/etc has display_errors = On.

The error_log directive tells PHP where to log errors to, but it also requires log_errors to be set to On, otherwise it has no effect. (Again, chances are the ini file in /private/etc has log_errors = Off.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文