How to log errors to a file in PHP using error_log

Home > Search > How-to
  by

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments