Can not set error_log option in PHP with ini_set

时间:2018-06-04 16:51:04

标签: php fpm

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 个答案:

答案 0 :(得分:1)

ini_set()全局工作,但并非所有设置都可以

ini_set()适用于php.ini中的全局设置。某些服务器设置为在HOST或PATH设置下设置值。 ini_set()无法更改这些特定值。