php 如何让php错误显示在syslog上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6469405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:28:29  来源:igfitidea点击:

how to get php errors to show on syslog

phperror-handlingsyslog

提问by madkris24

I have a script which is scheduled to run on crontab. I noticed that I could not see php errors anywhere. I wanted to be able to see php errors logged on /var/log/syslog or some place else. I have tried configuring my php.ini to log the errors on /var/log/php-errors.log, checked permissions and restarted the apache service still no logs.

我有一个计划在 crontab 上运行的脚本。我注意到我在任何地方都看不到 php 错误。我希望能够看到记录在 /var/log/syslog 或其他地方的 php 错误。我尝试配置我的 php.ini 以在 /var/log/php-errors.log 上记录错误,检查权限并重新启动 apache 服务仍然没有日志。

采纳答案by George Cummins

There are two issues to consider:

有两个问题需要考虑:

First, PHP CLI uses a different php.ini than the version of PHP that runs via Apache. Make sure you are editing the error_login the CLI version.

首先,PHP CLI 使用的 php.ini 与通过 Apache 运行的 PHP 版本不同。确保您正在error_logCLI 版本中编辑。

Second, make sure your log file is writable by the user that runs cron. Usually the logfile is not writable by your user account, so you may need to edit permissions.

其次,确保您的日志文件可由运行 cron 的用户写入。通常,您的用户帐户无法写入日志文件,因此您可能需要编辑权限。

回答by Femi

I have this in my /etc/php5/cli/php.inifile (I use Debian; I'm assuming its the same for whatever you are using) and it writes out all cron errors to /var/log/messages:

我的/etc/php5/cli/php.ini文件中有这个(我使用 Debian;我假设它与您使用的任何内容相同)并且它将所有 cron 错误写出到 /var/log/messages:

error_reporting  =  E_ALL & ~E_NOTICE
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 0
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
error_log = syslog

回答by Artefact2

Try error_log = syslogin your php.ini.

试试error_log = syslog你的 php.ini。

回答by Arie Skliarouk

On Ubuntu 16.04, the /dev/log is owned by group mysyslog (as defined by systemd). So for apache2/php to be able to write into syslog, you must add user www-data to group mysyslog: addgroup www-data mysyslog

在 Ubuntu 16.04 上,/dev/log 归 mysyslog 组所有(由 systemd 定义)。因此,为了使 apache2/php 能够写入 syslog,您必须将用户 www-data 添加到 mysyslog 组中: addgroup www-data mysyslog