Disabling error_log Files via .htaccess
If your error_log file is growing large and consuming disk space, you can control PHP error logging behavior through your .htaccess file.
Stop Writing to error_log
Add these lines to the .htaccess file in your public_html folder:
php_flag log_errors off
This stops PHP from writing errors to the error_log file entirely.
Better Approach: Keep Logging, Manage the File
Disabling error logging completely is not ideal because you lose visibility into problems. A better approach is to keep logging enabled but periodically clear or rotate the file:
- Delete the error_log: Simply delete the error_log file through File Manager or FTP. A new one will be created automatically if errors occur.
- Truncate it: Via SSH, run
> /home/username/public_html/error_logto empty the file without deleting it - Fix the underlying errors: The best long-term solution is to fix whatever is generating the errors. Open the error_log, look at the most recent entries, and address the PHP warnings or deprecated function calls.
Hiding Errors From Visitors
If PHP errors are displaying on your website pages (which is a security risk), add this to .htaccess:
php_flag display_errors off
This hides errors from visitors while still logging them to the error_log file so you can review them.
