PHP - Log errors to a file using error_log

by
Jeremy Canfield |
Updated: March 11 2020
| PHP articles
Follow these steps to configure PHP to allow errors to be logged to a file:
- In Terminal, type nano /etc/php.ini and press enter
- Press Ctrl W (to search), type log_errors and press enter
- Ensure log_errors = On
- Press Ctrl O (to save)
- 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