135 lines
3.5 KiB
Bash
Executable File
135 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Test Apache and PostfixAdmin Setup
|
|
# This script helps diagnose Apache and PostfixAdmin issues
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
info() {
|
|
echo -e "${BLUE}INFO: $1${NC}"
|
|
}
|
|
|
|
success() {
|
|
echo -e "${GREEN}SUCCESS: $1${NC}"
|
|
}
|
|
|
|
warning() {
|
|
echo -e "${YELLOW}WARNING: $1${NC}"
|
|
}
|
|
|
|
error() {
|
|
echo -e "${RED}ERROR: $1${NC}"
|
|
}
|
|
|
|
info "=== Apache and PostfixAdmin Diagnostic ==="
|
|
|
|
# Check Apache status
|
|
info "1. Checking Apache status..."
|
|
if systemctl is-active --quiet apache2; then
|
|
success "Apache is running"
|
|
else
|
|
error "Apache is not running"
|
|
echo "Try: systemctl start apache2"
|
|
fi
|
|
|
|
# Check listening ports
|
|
info "2. Checking listening ports..."
|
|
echo "Ports 80 and 443:"
|
|
ss -tlnp | grep -E ":(80|443) " || warning "No services listening on ports 80 or 443"
|
|
|
|
# Check Apache sites
|
|
info "3. Checking Apache sites..."
|
|
echo "Available sites:"
|
|
ls -la /etc/apache2/sites-available/ 2>/dev/null || warning "No sites-available directory"
|
|
|
|
echo "Enabled sites:"
|
|
ls -la /etc/apache2/sites-enabled/ 2>/dev/null || warning "No sites-enabled directory"
|
|
|
|
# Check PostfixAdmin directory
|
|
info "4. Checking PostfixAdmin installation..."
|
|
WEBROOT="/var/www/postfixadmin"
|
|
if [[ -d "$WEBROOT" ]]; then
|
|
success "PostfixAdmin directory exists: $WEBROOT"
|
|
echo "Contents:"
|
|
ls -la "$WEBROOT" | head -10
|
|
|
|
# Check if index.php exists
|
|
if [[ -f "$WEBROOT/index.php" ]]; then
|
|
success "index.php found"
|
|
elif [[ -f "$WEBROOT/public/index.php" ]]; then
|
|
success "index.php found in public directory"
|
|
warning "You may need to update DocumentRoot to $WEBROOT/public"
|
|
else
|
|
warning "index.php not found"
|
|
fi
|
|
|
|
# Check permissions
|
|
echo "Permissions:"
|
|
ls -ld "$WEBROOT"
|
|
else
|
|
error "PostfixAdmin directory not found: $WEBROOT"
|
|
fi
|
|
|
|
# Check PHP-FPM
|
|
info "5. Checking PHP-FPM..."
|
|
if systemctl is-active --quiet php*-fpm; then
|
|
success "PHP-FPM is running"
|
|
else
|
|
warning "PHP-FPM may not be running"
|
|
echo "Try: systemctl status php*-fpm"
|
|
fi
|
|
|
|
# Check Apache configuration
|
|
info "6. Testing Apache configuration..."
|
|
if apachectl configtest 2>/dev/null; then
|
|
success "Apache configuration is valid"
|
|
else
|
|
error "Apache configuration has errors:"
|
|
apachectl configtest
|
|
fi
|
|
|
|
# Check SSL certificates
|
|
info "7. Checking SSL certificates..."
|
|
HOSTNAME=$(hostname -f 2>/dev/null || hostname)
|
|
if [[ -f "/etc/letsencrypt/live/$HOSTNAME/fullchain.pem" ]]; then
|
|
success "SSL certificate found for $HOSTNAME"
|
|
else
|
|
warning "SSL certificate not found for $HOSTNAME"
|
|
echo "Check: ls -la /etc/letsencrypt/live/"
|
|
fi
|
|
|
|
# Check Apache error log
|
|
info "8. Recent Apache errors (last 10 lines):"
|
|
if [[ -f "/var/log/apache2/error.log" ]]; then
|
|
tail -10 /var/log/apache2/error.log
|
|
else
|
|
warning "Apache error log not found"
|
|
fi
|
|
|
|
# Test HTTP response
|
|
info "9. Testing HTTP response..."
|
|
if command -v curl &> /dev/null; then
|
|
echo "HTTP (port 80) response:"
|
|
curl -I -s http://localhost/ 2>/dev/null | head -5 || warning "No response on port 80"
|
|
|
|
echo "HTTPS (port 443) response:"
|
|
curl -I -s -k https://localhost/ 2>/dev/null | head -5 || warning "No response on port 443"
|
|
else
|
|
warning "curl not installed, cannot test HTTP responses"
|
|
fi
|
|
|
|
info "=== Diagnostic completed ==="
|
|
echo
|
|
info "If Apache is not working:"
|
|
echo "1. Check: journalctl -u apache2 -f"
|
|
echo "2. Check: /var/log/apache2/error.log"
|
|
echo "3. Try: systemctl restart apache2"
|
|
echo "4. Run: ./fix-apache.sh"
|