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"