Skip to content

Enabling and disabling PHP error logging using an .htaccess file

The log_errors directive in PHP controls whether error messages are logged to a file. The error_log directive specifies the location of the log file. On ruachost.com, you can configure these settings in a custom .htaccess file when you don’t have direct access to php.ini.

  • Enable logging: Capture errors for debugging and troubleshooting.
  • Disable logging: Reduce disk usage or prevent unnecessary logs in production.
  • Security: Keep error details out of public view while still recording them privately.

Steps to Configure Error Logging in .htaccess

Section titled “Steps to Configure Error Logging in .htaccess”
  • Log in to cPanel or use FTP/File Manager.
  • Navigate to your site’s root directory (e.g., /public_html).
  1. If .htaccess already exists, open it for editing.
  2. If not, create a new file named .htaccess.
php_flag log_errors On
php_value error_log /home/USERNAME/logs/php_errors.log
  • Replace /home/USERNAME/logs/php_errors.log with the full path to your desired log file.
  • Ensure the directory exists and is writable.
php_flag log_errors Off
  1. Save the .htaccess file.

  2. Create a test file with an intentional error:

    <?php echo $undefined_variable; ?>
  3. Load it in your browser.

    • If logging is enabled, check the log file for entries.
    • If disabled, no new entries should appear.
  • Keep logs outside the public web root for security.
  • Rotate or clear logs regularly to prevent large files.
  • Use display_errors = Off in production to avoid exposing sensitive details.