简体   繁体   English

PHP未写入错误日志

[英]PHP not writing to error log

File structure setup like so, 像这样设置文件结构,

mainDirectory
-app
--logs
---errors.log
-file.php

Inside of file.php I have, file.php里面,

ini_set("log_errors", 1);
ini_set("error_log", "logs/errors.log");

I then try to output results like this later, 然后,我稍后尝试输出这样的结果,

error_log( print_r($response, TRUE) );

However it just dumps to console. 但是,它只是转储到控制台。 I then tried various checks like 然后我尝试了各种检查

if( file_exists( "logs/errors.log" ) ) {
    echo 'yup';
}
else {
    echo 'nope';
}

And each time is "nope" 而且每次都是“不”

Am I missing something obvious here? 我在这里错过明显的东西吗?

Thank you. 谢谢。

My guess is that you're running into a permissions problem. 我的猜测是您遇到权限问题。 I'm running Apache on OSX Sierra and my log files are stored in /var/log. 我在OSX Sierra上运行Apache,我的日志文件存储在/ var / log中。 If I try to the line below, I get a permission denied error. 如果我尝试转到下面的行, permission denied出现permission denied错误。

file_put_contents('/var/log/apache2/errors2.log', 'Hello world');

You might consider choosing a location for your error_log that you are certain Apache has permission to write to like /tmp . 您可能会考虑为error_log选择一个可以确定Apache有权写入类似/tmp

ini_set("error_log", "/tmp/errors.log");

Try using file_put_contents to test the permissions of the directory before using ini_set which can be a bit terse. 在使用ini_set之前,请尝试使用file_put_contents来测试目录的权限,这可能会有点简洁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM