Enhance 500 tracker error log detection and .htaccess diagnosis

IMPROVED ERROR LOG DETECTION:
- Now checks 5 different locations for error logs:
  • /home/USER/public_html/error_log
  • /home/USER/logs/error_log
  • /home/USER/error_log
  • /var/log/apache2/domlogs/DOMAIN-error_log
  • /usr/local/apache/domlogs/DOMAIN
- Increased tail from 100 to 500 lines for better error capture

NEW .HTACCESS DETECTION:
- If no error_log found, checks for .htaccess file
- Looks for RewriteRules, php_value, php_flag directives
- If found, classifies as 'HTACCESS_LIKELY' instead of 'NO_ERROR_LOG_FILE'
- Provides specific .htaccess troubleshooting steps

BETTER ROOT CAUSE CATEGORIES:
- HTACCESS_LIKELY: Has .htaccess with rules, likely syntax error
- NO_ERROR_LOG_FILE: Checked all locations, truly not found
- NO_PHP_ERROR_LOGGED: Error log exists but empty (Apache/config issue)

This should catch most of the 'NO_ERROR_LOG_FILE' cases and
correctly identify them as .htaccess syntax errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cschantz
2025-11-03 20:42:19 -05:00
parent ab70a6e569
commit e4eaf9afb5
+44 -8
View File
@@ -146,13 +146,28 @@ declare -A cause_examples
while IFS='|' read -r domain user status url timestamp ip; do while IFS='|' read -r domain user status url timestamp ip; do
[ -z "$domain" ] && continue [ -z "$domain" ] && continue
# Find PHP error log for this user # Find PHP error log - check multiple locations
error_log="/home/$user/public_html/error_log" error_log=""
if [ "$user" != "unknown" ]; then
# Try multiple possible locations
for potential_log in \
"/home/$user/public_html/error_log" \
"/home/$user/logs/error_log" \
"/home/$user/error_log" \
"/var/log/apache2/domlogs/$domain-error_log" \
"/usr/local/apache/domlogs/$domain"; do
if [ -f "$potential_log" ]; then
error_log="$potential_log"
break
fi
done
fi
# Check if error log exists and has recent errors # Check if error log exists and has recent errors
if [ -f "$error_log" ]; then if [ -n "$error_log" ] && [ -f "$error_log" ]; then
# Look for errors around the same time as the 500 # Look for errors around the same time as the 500
recent_error=$(tail -100 "$error_log" | grep -E "Fatal error|Parse error|syntax error|memory.*exhausted|database|MySQL" | tail -1) recent_error=$(tail -500 "$error_log" | grep -E "Fatal error|Parse error|syntax error|memory.*exhausted|database|MySQL|Permission denied" | tail -1)
if [ -n "$recent_error" ]; then if [ -n "$recent_error" ]; then
# Determine cause # Determine cause
@@ -181,8 +196,22 @@ while IFS='|' read -r domain user status url timestamp ip; do
((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++)) ((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++))
fi fi
else else
((diagnosed_causes["NO_ERROR_LOG_FILE"]++)) # No error log found - likely .htaccess issue
cause_examples["NO_ERROR_LOG_FILE"]="$domain (user: $user) - error_log file missing at $error_log" # Check if .htaccess exists and might have issues
if [ "$user" != "unknown" ] && [ -f "/home/$user/public_html/.htaccess" ]; then
# Check for common .htaccess syntax errors
htaccess_check=$(grep -E "RewriteEngine|RewriteRule|RewriteCond|php_value|php_flag" "/home/$user/public_html/.htaccess" 2>/dev/null)
if [ -n "$htaccess_check" ]; then
((diagnosed_causes["HTACCESS_LIKELY"]++))
cause_examples["HTACCESS_LIKELY"]="$domain (user: $user) - has .htaccess with rewrite rules, check syntax"
else
((diagnosed_causes["NO_ERROR_LOG_FILE"]++))
cause_examples["NO_ERROR_LOG_FILE"]="$domain (user: $user) - checked multiple locations, no error_log found"
fi
else
((diagnosed_causes["NO_ERROR_LOG_FILE"]++))
cause_examples["NO_ERROR_LOG_FILE"]="$domain (user: $user) - checked multiple locations, no error_log found"
fi
fi fi
done < "$ERRORS_500" done < "$ERRORS_500"
@@ -218,13 +247,20 @@ done | sort -rn | while IFS='|' read count cause; do
echo -e "${RED}🗄️ $clean_cause${NC} - $count occurrences" echo -e "${RED}🗄️ $clean_cause${NC} - $count occurrences"
echo " ${YELLOW}Fix:${NC} Check database credentials or MySQL service" echo " ${YELLOW}Fix:${NC} Check database credentials or MySQL service"
;; ;;
HTACCESS_LIKELY)
echo -e "${RED}⚙️ .HTACCESS SYNTAX ERROR (LIKELY)${NC} - $count occurrences"
echo " ${YELLOW}Fix:${NC} Check .htaccess file for syntax errors"
echo " ${YELLOW}Test:${NC} Temporarily rename .htaccess to .htaccess.bak and test"
echo " ${YELLOW}Common issues:${NC} Invalid RewriteRule, bad php_value directives"
;;
NO_ERROR_LOG_FILE) NO_ERROR_LOG_FILE)
echo -e "${YELLOW}📄 $clean_cause${NC} - $count occurrences" echo -e "${YELLOW}📄 $clean_cause${NC} - $count occurrences"
echo " ${YELLOW}Note:${NC} error_log file doesn't exist - may be .htaccess or permission issue" echo " ${YELLOW}Note:${NC} Checked multiple error_log locations - none found"
echo " ${YELLOW}Check:${NC} May need to enable PHP error logging"
;; ;;
NO_PHP_ERROR_LOGGED) NO_PHP_ERROR_LOGGED)
echo -e "${YELLOW}$clean_cause${NC} - $count occurrences" echo -e "${YELLOW}$clean_cause${NC} - $count occurrences"
echo " ${YELLOW}Note:${NC} 500 error but no PHP error in log - likely .htaccess issue" echo " ${YELLOW}Note:${NC} 500 error but no PHP error in log - likely .htaccess or Apache config"
;; ;;
*) *)
echo -e "${INFO_COLOR}$clean_cause${NC} - $count occurrences" echo -e "${INFO_COLOR}$clean_cause${NC} - $count occurrences"