Can not set error_log option in PHP with ini_set

会有一股神秘感。 提交于 2019-12-20 05:18:10

问题


I'm running PHP 7 on Ubuntu Xenial, and bumped into a weird situation with WordPress. I was attempting to enable WP_DEBUG_LOG and it wasn't writing out to the debug log file.

I wrote up a small test case and I can't figure out why this is happening. I do not change the default config for safe_mode or open_basedir which my Googling led me to believe would be the culprits.

Script

<?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));

Output

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

The direct write with file_put_contents works, but the error_log one does not, obviously because the call to ini_set('error_log') returns false.

What other things could cause this?

Edit: Mon Jun 4 16:40:35 CDT 2018

Thanks to comments on here, I found that had used php_admin_value in my PHP-FPM config, which makes a setting immutable.

Any directive type set with php_admin_value can not be overridden by .htaccess or ini_set().

http://php.net/manual/en/configuration.changes.php


回答1:


ini_set() works globally, but not all settings do

ini_set() works on global settings in php.ini. Some servers are set up to have values set under a HOST or a PATH setting. ini_set() can not change these particular values.



来源:https://stackoverflow.com/questions/50685334/can-not-set-error-log-option-in-php-with-ini-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!