From e4eaf9afb544ff5a7255e8ecd05921e418f87102 Mon Sep 17 00:00:00 2001 From: cschantz Date: Mon, 3 Nov 2025 20:42:19 -0500 Subject: [PATCH] Enhance 500 tracker error log detection and .htaccess diagnosis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- modules/website/500-error-tracker.sh | 58 ++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/modules/website/500-error-tracker.sh b/modules/website/500-error-tracker.sh index 8c133d2..86f9e4e 100755 --- a/modules/website/500-error-tracker.sh +++ b/modules/website/500-error-tracker.sh @@ -145,15 +145,30 @@ declare -A cause_examples while IFS='|' read -r domain user status url timestamp ip; do [ -z "$domain" ] && continue - - # Find PHP error log for this user - error_log="/home/$user/public_html/error_log" - + + # Find PHP error log - check multiple locations + 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 - if [ -f "$error_log" ]; then + if [ -n "$error_log" ] && [ -f "$error_log" ]; then # 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 # Determine cause cause="UNKNOWN" @@ -181,8 +196,22 @@ while IFS='|' read -r domain user status url timestamp ip; do ((diagnosed_causes["NO_PHP_ERROR_LOGGED"]++)) fi else - ((diagnosed_causes["NO_ERROR_LOG_FILE"]++)) - cause_examples["NO_ERROR_LOG_FILE"]="$domain (user: $user) - error_log file missing at $error_log" + # No error log found - likely .htaccess issue + # 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 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 " ${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) 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) 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"