我在Ubuntu Xenial上运行PHP7,在使用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。
还有什么其他原因会导致这种情况?
编辑: Mon 4 16:40:35 CDT 2018
多亏了这里的评论,我发现在我的PHP-FPM配置中使用了php_admin_value
,这使得设置是不可变的。
使用php_admin_value设置的任何指令类型都不能被.htaccess或ini_set()覆盖。
发布于 2018-06-05 05:43:12
ini_set()可以全局使用,但并非所有设置都支持
ini_set()作用于php.ini中的全局设置。某些服务器设置为在主机或路径设置下设置值。ini_set()不能更改这些特定值。
https://stackoverflow.com/questions/50685334
复制相似问题