skip to Main Content

Server: AlmaLinux 8, PHP 8.2.2

I have many servers with variety of PHP versions, on most the code below logs correctly to the specified error log file. The server I have a problem with was just upgraded to PHP 8.2.2.

I have in my php.ini

// I have tried a variety of settings
error_reporting = E_ALL
log_errors = On
display_errors = Off
html_errors = Off
error_log = /var/log/php

I have a bit of code (just the important bits)

<?php
error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('display_errors', 0);
ini_set('error_log','/var/log/php');
mysqli_report(MYSQLI_REPORT_OFF);

// debug message
error_log("start of script");

// removed the error handling in the code
// the connection works, I know!
$MJCONN = mysqli_connect($hostname, $username, $password);
mysqli_select_db($MJCONN, $database);

// many lines of code deleted

if(!$result = mysqli_query($MJCONN, $TheQuery)) {
  error_log("It's dead Jim");
  exit;
}

// many lines of code deleted

// here is my error, I mispelled the variable name
while($r = mysqli_fetch_assoc($resulr))
{
  // some code here
} 
?>

The debug message using error_log("start of script") is correctly shown in the file, so this is NOT a permission error.

Whatever I try, the mispelled variable name error is never displayed in the log file. I even tried to mispell a function name, same nothing is displayed in the error_log file.

If I set this:

error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('display_errors', 1);
ini_set('error_log','/var/log/php');

It works correctly and the error is displayed on the screen, which is NOT what I want.
I want syntax – or preferably all errors – logged in the error_log.

What am I doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    Turns out the default config file for php-fpm has changed. It now comes with a default setting

    php_admin_value[error_log] = /var/log/php-fpm/www-error.log
    php_admin_flag[log_errors] = on
    

    The problem with this it absolute overrides ini_set, so the following code

    ini_set('error_log','/var/log/php')
    

    has no meaning anywhere in your code.

    If you comment out this code like so

    ;php_admin_value[error_log] = /var/log/php-fpm/www-error.log
    

    the setting in php.ini takes over again, but the error formatting is in shambles, the only way to fix all of this it to

    php_admin_value[error_log] = /var/log/php
    php_admin_flag[log_errors] = on
    

    to get it well formatted back to the original location, but ini_set will still not work.


  2. Please check which php.ini configure file was loaded by PHP 8.2.2,
    You can used command line to check the php.ini file used :

    $ php -i | grep 'Configuration File'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search