Enabling PHP error logging
PHP error logging helps you identify and troubleshoot issues in your scripts. On ruachost.com, you can configure error logging using the php.ini file or .user.ini depending on your hosting environment.
Why Enable Error Logging?
Section titled “Why Enable Error Logging?”- Detect syntax and runtime errors in your PHP scripts.
- Monitor application behavior for debugging.
- Improve security by keeping error details out of public view.
Steps to Enable PHP Error Logging
Section titled “Steps to Enable PHP Error Logging”Step 1: Create or Edit a Custom php.ini File
Section titled “Step 1: Create or Edit a Custom php.ini File”Add the following directives:
log_errors = Onerror_log = /home/USERNAME/logs/php_errors.log- Replace
USERNAMEwith your Ruachost account username. - Ensure the
logsdirectory exists and is writable.
Step 2: Using .user.ini (Alternative Method)
Section titled “Step 2: Using .user.ini (Alternative Method)”If your hosting environment supports .user.ini, add:
log_errors = Onerror_log = /home/USERNAME/logs/php_errors.logStep 3: Verify Settings
Section titled “Step 3: Verify Settings”-
Create a test script with an intentional error:
<?phpecho $undefined_variable;?> -
Run the script in your browser.
-
Check the log file (
php_errors.log) for the error entry.
Disabling Error Logging
Section titled “Disabling Error Logging”To turn off error logging, modify the directive:
log_errors = OffBest Practices
Section titled “Best Practices”- Store logs outside the public web root for security.
- Rotate or clear logs regularly to prevent large files.
- Use
display_errors = Offin production to avoid exposing sensitive details. - Monitor logs frequently to catch issues early.