0

Recently we migrated PHP version of our webapp from version 5.[something] to 7.2, and our apache2 php.ini is setup to avoid notices logging both in the server and the browser. I am told that before the migration the setup worked fine, but now notices show up all over the place.

This is the setup:

error_reporting = E_ALL & ~E_NOTICE

I have tried

error_reporting = E_ALL ^ (E_DEPRECATED & E_NOTICE)

too, to no avail. There is no .htaccess file overriding the setup and when I set the error_reporting variable to something different the application reports a change in the error_reporting state, it's just that when I specify that I don't want the E_NOTICEs, the setup does not work.

This is the snippet of configuration that deals with the errors:

display_errors = On
;error_reporting = E_ALL ^ E_DEPRECATED
;error_reporting = E_ALL ^ (E_DEPRECATED & E_NOTICE)
;error_reporting = E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR
error_reporting = E_ALL & ~E_NOTICE
;E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE

We would like to avoid logging the notices both in the server and in the browser. Any ideas on what may be wrong?

Thanks!

  • Are you sure that is the correct `php.ini`? Check `phpinfo()` for the loaded file. – AbraCadaver May 14 '19 at 15:06
  • Also, if you are logging (you didn't show those settings) then `display_errors = Off`. And you need to restart Apache after changing `php.ini`. – AbraCadaver May 14 '19 at 15:07
  • Hi! Apache2 was restarted every time, I added phpinfo() to the index.php file that handles the app booting and it printed a table with a row stating Loaded Configuration File /etc/php/7.2/apache2/php.ini. So I can confirm that the .ini file I was editing is the right one. – Ravalo Manana May 15 '19 at 08:18

2 Answers2

0

I suggest you, instead of hiding notices try writing php applications that do not produce notices. Hiding this information is not a good programming technique and often leave unresolved vulnerabilities or bugs.

Anyway your problem can be solved putting into your script (at beginning):

error_reporting(E_ALL ^ E_NOTICE);

This will turn off notices...

I suggest you to read the manual

To set this value in your php.ini (php.ini is not an Apache configuration file, it's a php configuration file) you can use (as you are already using):

error_reporting = E_ALL & ~E_NOTICE

and don't forget to change

display_errors = On

with

display_errors = Off

in your php.ini, don't forget to stop Apache and restart it again to see the changes...

See this thread and this thread

Hope this helps.

Alessandro
  • 900
  • 12
  • 23
  • Apache was restarted every time. I added the error_reporting invocation you added to the very first application code file that is executed, but the issue persists. There are no other error_reporting calls in the app. What we want is to be able to see the errors without notices in the browser (so display_errors = On) during development and be able to log them in production without seeing them in the browser and without all the notices. Otherwise log files would soon become too big. – Ravalo Manana May 15 '19 at 08:35
  • With the error_reporting() call in place phpinfo() returns error_reporting to be 32759 both in local value and master value. Notices still show up. – Ravalo Manana May 15 '19 at 08:45
  • yes, the only difference from the setup suggested is that we want the errors to appear in our logging, apart from the notices. So the filter should be set in error_reporting. Turning off html_errors only removes the html formatting from the notices, they still show up. – Ravalo Manana May 15 '19 at 09:23
  • You said: "What we want is to be able to see the errors without notices in the browser (so display_errors = On) during development and be able to log them in production without seeing them in the browser and without all the notices." You remember that PHP comes with two (2) differents php.ini? One for develop and second for production? You want combine the features of develop and production into one single configuration file? IMHO it's not possible. – Alessandro May 15 '19 at 18:54
  • basically we needed two different setups – Ravalo Manana May 16 '19 at 07:13
0

We managed to solve the issue, one of our libraries (cache-lite by PEAR) had a line of code that programmatically set logging codes in the file /usr/share/php/Cache/Lite.php at line 25, here it is

error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);

we commented it out and everything works fine now. Thanks everybody!