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

Nginx redirecting folder to another host or server

From time to time you may want to proxy out a path to another server or location. To perform a...

How to create a temporary 302 redirect via htaccess

An easy way to create a temporary redirect from one page to another web page is to use the 302...

Permission denied: /home/username/ htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

When checking your error log you find the error 508 or 403 forbidden error in your browser and...

htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

To solve “.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable” follow...

Redirecting non-www to www with htaccess

Redirecting non-www to www with .htaccessIf you ever point your www. record to another server...



Save 30% on web hosting - Use coupon code Hosting30