Can not set error_log option in PHP with ini_set

jmhobbs

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

Michael W.

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ini_set for connected php files advices

PHP ini_set memory limit

How to set different path for php error_log file?

ini_set is NOT setting the values inside php.ini

ini_set fails to set session variables – PHP 7.2.0 and higher

PHP - ini_set() expects parameter 2 to be string, integer given

i moved opencart on another domain and error ini_set() is disable

log_errors and error_log in php for php.ini

What difference does usage of symbol @ with ini_set, built-in function makes in PHP?

Is it fine if I would use ini_set("memory_limit",-1); in my php file

SilverStripe installation gives error "date.timezone option in php.ini must be set correctly." even when timezone is set

Where is file ini_set in windows 10 i why have error in this script

How to add custom ini_set in Laravel

PHP: Does ini_set("memory_limit","1024M"); implicitly relase memory resources on PHP script execution end?

ini_set() is not blocked, yet I get "Warning: ini_set() has been disabled for security reasons"

mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

PHP7.2.7-fpm/Docker ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Can I set any of these statements in php.ini

How to disable "ini_set" and "exec" for a particular VirtualHost?

ini_set 'session.gc_maxlifetime' for 1 day

sylius:install: Warning: ini_set(): A session is active

Is using ini_set in a script considered bad practice?

Warning: ini_set() has been disabled for security reasons

What is the PSR-1 Compliant Alternative to Using ini_set()?

Can a Bash shell option be set for a single command?

How to set the select option can be type by numbers

I can't put my options into a PHP file and set the selected option by using a URL parameter

How to dynamically set an option selected in PHP

set option selected using php value