Today we’re going to learn how to create a handler to redirect PHP errors to the Linux or Docker console.

The first thing we need to do is to create a handler, we can call it exception_handler.php.
And let’s add the following:
This function will give us all the necessary information to identify the error, the error message, the file, the line, and the error code. In addition to the date and the IP from where the call was made.
NOTE: you must put $_SERVER[‘HTTP_X_REAL_IP’] if you use a reverse proxy, instead of $_SERVER[‘REMOTE_ADDR’];
Now we just have to include this file in the files that we want to audit errors by doing an include:
include_once('../extras/exception_handler.php');
