Improve diagnosis: check .htaccess even when error_log exists

Problem: Only diagnosing 4 unique issues out of 7555 errors because script
was only checking .htaccess when error_log didn't exist. Most errors had
error_log files but no matching PHP errors, so fell through to
"NO_PHP_ERROR_LOGGED" without further investigation.

Solution: Added fallback .htaccess checking in two scenarios:
1. When error_log exists but has no matching errors for this URL
2. When error_log exists but grep finds no relevant PHP errors

Now checks for common .htaccess issues in all cases:
- Invalid php_value/php_flag directives (incompatible with FPM)
- Malformed RewriteRule syntax

This should dramatically increase the number of diagnosed issues by catching
.htaccess problems even when PHP error_log exists.
This commit is contained in:
cschantz
2025-11-03 21:34:22 -05:00
parent abdcb906d8
commit 9dba9c7642
+60 -2
View File
@@ -349,10 +349,68 @@ while IFS='|' read -r domain user status url timestamp ip; do
((diagnosed_causes["$cause"]++)) ((diagnosed_causes["$cause"]++))
[ -z "${cause_examples[$cause]}" ] && cause_examples["$cause"]="$diagnosis" [ -z "${cause_examples[$cause]}" ] && cause_examples["$cause"]="$diagnosis"
else else
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++)) # No matching error in error_log - check .htaccess as fallback
if [ "$user" != "unknown" ] && [ -f "$docroot/.htaccess" ]; then
htaccess_file="$docroot/.htaccess"
htaccess_issues=""
# Check for invalid PHP directives
if grep -qE "^[[:space:]]*(php_value|php_flag|php_admin_value|php_admin_flag)" "$htaccess_file" 2>/dev/null; then
if ! apache2ctl -M 2>/dev/null | grep -q "php.*module"; then
htaccess_issues="PHP directives (php_value/php_flag) incompatible with current PHP handler (not mod_php)"
fi
fi
# Check for malformed RewriteRule
bad_rewrite=$(grep -nE "RewriteRule.*\[.*[^]]*$" "$htaccess_file" 2>/dev/null | head -1)
if [ -n "$bad_rewrite" ]; then
htaccess_issues="${htaccess_issues:+$htaccess_issues; }Malformed RewriteRule: $bad_rewrite"
fi
if [ -n "$htaccess_issues" ]; then
cause="HTACCESS_ERROR"
diagnosis="$domain$url - .htaccess error: $htaccess_issues"
echo "$cause|$diagnosis" >> "$DETAILED_DIAGNOSIS"
((diagnosed_causes["$cause"]++))
[ -z "${cause_examples[$cause]}" ] && cause_examples["$cause"]="$diagnosis"
else
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++))
fi
else
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++))
fi
fi fi
else else
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++)) # No error in error_log at all - check .htaccess
if [ "$user" != "unknown" ] && [ -f "$docroot/.htaccess" ]; then
htaccess_file="$docroot/.htaccess"
htaccess_issues=""
# Check for invalid PHP directives
if grep -qE "^[[:space:]]*(php_value|php_flag|php_admin_value|php_admin_flag)" "$htaccess_file" 2>/dev/null; then
if ! apache2ctl -M 2>/dev/null | grep -q "php.*module"; then
htaccess_issues="PHP directives (php_value/php_flag) incompatible with current PHP handler (not mod_php)"
fi
fi
# Check for malformed RewriteRule
bad_rewrite=$(grep -nE "RewriteRule.*\[.*[^]]*$" "$htaccess_file" 2>/dev/null | head -1)
if [ -n "$bad_rewrite" ]; then
htaccess_issues="${htaccess_issues:+$htaccess_issues; }Malformed RewriteRule: $bad_rewrite"
fi
if [ -n "$htaccess_issues" ]; then
cause="HTACCESS_ERROR"
diagnosis="$domain$url - .htaccess error: $htaccess_issues"
echo "$cause|$diagnosis" >> "$DETAILED_DIAGNOSIS"
((diagnosed_causes["$cause"]++))
[ -z "${cause_examples[$cause]}" ] && cause_examples["$cause"]="$diagnosis"
else
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++))
fi
else
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++))
fi
fi fi
else else
# No error log found - check .htaccess and permissions thoroughly # No error log found - check .htaccess and permissions thoroughly