Bootstrap FreeKB - PHP - Log errors to a file using error_log
PHP - Log errors to a file using error_log

Updated:   |  PHP articles

Follow these steps to configure PHP to allow errors to be logged to a file:

  1. In Terminal, type nano /etc/php.ini and press enter
  2. Press Ctrl W (to search), type log_errors and press enter
  3. Ensure log_errors = On
  4. Press Ctrl O (to save)
  5. Press Ctrl W (to exit the nano editor)

Create the following PHP file to test error_log.

<?php
$x = 1;
if ($x != 2) 
  {
    error_log("Example error", 3, "/var/tmp/error.log");
  }
?>

 

View the error log to ensure the error log contians "Example error":

[root@server1 ]# cat /var/tmp/error.log
Example error

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter ee4bf9 in the box below so that we can be sure you are a human.