【发布时间】:2018-06-04 16:51:04
【问题描述】:
我在 Ubuntu Xenial 上运行 PHP 7,在使用 WordPress 时遇到了一个奇怪的情况。我试图启用WP_DEBUG_LOG,但它没有写入调试日志文件。
我写了一个小测试用例,但我不知道为什么会这样。我不会更改 safe_mode 或 open_basedir 的默认配置,我的谷歌搜索让我相信这将是罪魁祸首。
脚本
<?php
header('Content-Type: text/plain');
define('DEBUG_LOG', '/www/wp-content/debug.log');
echo "PHP Version: " . phpversion() . "\n";
echo "PHP SAPI: " . php_sapi_name() . "\n";
echo "safe_mode: "; var_dump(ini_get('safe_mode'));
echo "open_basedir: "; var_dump(ini_get('open_basedir'));
echo "error_log: "; var_dump(ini_get('error_log'));
echo "Permissions: " . substr(sprintf('%o', fileperms(DEBUG_LOG)), -4) . "\n";
file_put_contents(DEBUG_LOG, "Direct Write\n", FILE_APPEND);
echo "Setting log_errors: "; var_dump(ini_set('log_errors', true));
echo "Setting error_log: "; var_dump(ini_set('error_log', DEBUG_LOG));
error_log('Testing error_log');
die(file_get_contents(DEBUG_LOG));
输出
PHP Version: 7.2.5-1+ubuntu16.04.1+deb.sury.org+1
PHP SAPI: fpm-fcgi
safe_mode: bool(false)
open_basedir: string(0) ""
error_log: string(22) "/var/log/php_error.log"
Permissions: 0777
Setting log_errors: string(1) "1"
Setting error_log: bool(false)
Direct Write
使用file_put_contents 直接写入有效,但error_log 无效,显然是因为对ini_set('error_log') 的调用返回false。
还有什么其他原因会导致这种情况?
编辑:2018 年 6 月 4 日星期一 16:40:35 CDT
感谢 cmets on here,我发现在我的 PHP-FPM 配置中使用了 php_admin_value,这使得设置不可变。
任何用 php_admin_value 设置的指令类型都不能被 .htaccess 或 ini_set() 覆盖。
【问题讨论】:
-
php.ini 的 HOST 或 PATH 部分是否有 error_log?这可能会与 ini_set() 混淆。
-
什么操作系统?
/www/wp-content/debug.log对我来说似乎是无效的路径。应该是/var/www/html/wp-content/debug.log或/var/www/wp-content/debug.log -
Alex - Ubuntu Xenial - 路径是自定义的,但它都归 www-data 所有。
-
Michael - 我的 FPM 池配置中有一个自定义路径,
php_admin_value[error_log] = /var/log/php_error.log。我会尝试清除它,谢谢。 -
@MichaelW。就是这样!想要给出答案以便我接受吗?