Disable error_log via htaccess

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_log to 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.

  • 136 Users Found This Useful

Was this answer helpful?

Related Articles

301 Redirect

This code will redirect all visitors who attempt to access the old-url.html page to the...

What are these htaccess files that keep popping up?

Why .htaccess Files Keep Appearing in My Directories   If you notice .htaccess files...

Show longer file names in directory/folder index

If you've ever wanted to show longer file names in your directory listing just create or edit an...

Complete Guide to .htaccess on Apache

The Complete Guide to .htaccess for Web Hosting   The .htaccess file is one of the most...

Redirect http to https and www

To forward a website to use both www. and https:// use the following in an .htaccess file:...



Save 30% on web hosting - Use coupon code Hosting30