Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/server_check.php

<?php
/**
 * Server Environment Check
 * Run this on your live server to diagnose 500 errors
 * Access: http://yourdomain.com/server_check.php
 */

// Enable error display temporarily for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Server Environment Check</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
        .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
        h1 { color: #333; border-bottom: 3px solid #1E40AF; padding-bottom: 10px; }
        h2 { color: #1E40AF; margin-top: 30px; }
        .success { color: #10B981; font-weight: bold; }
        .error { color: #EF4444; font-weight: bold; }
        .warning { color: #F59E0B; font-weight: bold; }
        .info { background: #EFF6FF; padding: 15px; border-left: 4px solid #1E40AF; margin: 10px 0; }
        .check-item { padding: 10px; margin: 5px 0; border: 1px solid #e5e7eb; border-radius: 4px; }
        table { width: 100%; border-collapse: collapse; margin: 10px 0; }
        th, td { padding: 10px; text-align: left; border-bottom: 1px solid #e5e7eb; }
        th { background: #f9fafb; font-weight: bold; }
        code { background: #f3f4f6; padding: 2px 6px; border-radius: 3px; font-family: monospace; }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔍 Server Environment Check</h1>
        <p><strong>Run Date:</strong> <?php echo date('Y-m-d H:i:s'); ?></p>

        <?php
        $errors = [];
        $warnings = [];
        $checks = [];

        // 1. PHP Version Check
        echo "<h2>1. PHP Version</h2>";
        $phpVersion = phpversion();
        echo "<div class='check-item'>";
        echo "<strong>PHP Version:</strong> $phpVersion<br>";
        if (version_compare($phpVersion, '7.4.0', '>=')) {
            echo "<span class='success'>✓ PHP version is compatible</span>";
        } else {
            echo "<span class='error'>✗ PHP 7.4+ required. Current: $phpVersion</span>";
            $errors[] = "PHP version too old";
        }
        echo "</div>";

        // 2. Required PHP Extensions
        echo "<h2>2. Required PHP Extensions</h2>";
        $requiredExtensions = [
            'pdo' => 'Database connectivity',
            'pdo_mysql' => 'MySQL database driver',
            'gd' => 'Image processing (QR codes, barcodes)',
            'mbstring' => 'Multi-byte string handling',
            'zip' => 'ZIP file handling',
            'curl' => 'External HTTP requests',
            'openssl' => 'SSL/TLS support',
            'json' => 'JSON parsing',
            'xml' => 'XML processing',
            'fileinfo' => 'File type detection'
        ];

        echo "<table>";
        echo "<tr><th>Extension</th><th>Purpose</th><th>Status</th></tr>";
        foreach ($requiredExtensions as $ext => $purpose) {
            $loaded = extension_loaded($ext);
            echo "<tr>";
            echo "<td><code>$ext</code></td>";
            echo "<td>$purpose</td>";
            echo "<td>" . ($loaded ? "<span class='success'>✓ Loaded</span>" : "<span class='error'>✗ Missing</span>") . "</td>";
            echo "</tr>";
            if (!$loaded) {
                $errors[] = "Missing extension: $ext";
            }
        }
        echo "</table>";

        // 3. File System Checks
        echo "<h2>3. File System & Permissions</h2>";
        
        $dirsToCheck = [
            'config' => __DIR__ . '/config',
            'uploads' => __DIR__ . '/uploads',
            'classes' => __DIR__ . '/classes',
            'vendor' => __DIR__ . '/vendor'
        ];

        echo "<table>";
        echo "<tr><th>Directory</th><th>Exists</th><th>Writable</th><th>Path</th></tr>";
        foreach ($dirsToCheck as $name => $path) {
            $exists = is_dir($path);
            $writable = $exists && is_writable($path);
            echo "<tr>";
            echo "<td><strong>$name/</strong></td>";
            echo "<td>" . ($exists ? "<span class='success'>✓</span>" : "<span class='error'>✗</span>") . "</td>";
            echo "<td>" . ($writable ? "<span class='success'>✓</span>" : "<span class='error'>✗</span>") . "</td>";
            echo "<td><code>$path</code></td>";
            echo "</tr>";
            
            if (!$exists) {
                $errors[] = "Directory missing: $name";
            } elseif ($name === 'uploads' && !$writable) {
                $errors[] = "Directory not writable: $name";
            }
        }
        echo "</table>";

        // 4. Config File Check
        echo "<h2>4. Configuration Files</h2>";
        $configFile = __DIR__ . '/config/config.php';
        $dbConfigFile = __DIR__ . '/config/database.php';
        
        echo "<div class='check-item'>";
        echo "<strong>config.php:</strong> ";
        if (file_exists($configFile)) {
            echo "<span class='success'>✓ Found</span><br>";
            echo "<code>" . realpath($configFile) . "</code>";
        } else {
            echo "<span class='error'>✗ Missing</span>";
            $errors[] = "config.php not found";
        }
        echo "</div>";

        echo "<div class='check-item'>";
        echo "<strong>database.php:</strong> ";
        if (file_exists($dbConfigFile)) {
            echo "<span class='success'>✓ Found</span><br>";
            echo "<code>" . realpath($dbConfigFile) . "</code>";
        } else {
            echo "<span class='error'>✗ Missing</span>";
            $errors[] = "database.php not found";
        }
        echo "</div>";

        // 5. Try to load config
        echo "<h2>5. Configuration Loading Test</h2>";
        echo "<div class='check-item'>";
        try {
            if (file_exists($configFile)) {
                require_once $configFile;
                echo "<span class='success'>✓ Config loaded successfully</span><br>";
                
                // Check if constants are defined
                $constants = ['APP_NAME', 'BASE_URL', 'DB_HOST', 'DB_NAME', 'DB_USER'];
                echo "<br><strong>Defined Constants:</strong><br>";
                foreach ($constants as $const) {
                    if (defined($const)) {
                        $value = constant($const);
                        // Mask password
                        if ($const === 'DB_PASS') {
                            $value = str_repeat('*', strlen($value));
                        }
                        echo "• <code>$const</code> = " . htmlspecialchars($value) . "<br>";
                    } else {
                        echo "• <code>$const</code> <span class='warning'>⚠ Not defined</span><br>";
                        $warnings[] = "Constant not defined: $const";
                    }
                }
            }
        } catch (Exception $e) {
            echo "<span class='error'>✗ Error loading config:</span><br>";
            echo "<code>" . htmlspecialchars($e->getMessage()) . "</code>";
            $errors[] = "Config loading failed: " . $e->getMessage();
        }
        echo "</div>";

        // 6. Database Connection Test
        echo "<h2>6. Database Connection Test</h2>";
        echo "<div class='check-item'>";
        try {
            if (defined('DB_HOST') && defined('DB_NAME') && defined('DB_USER') && defined('DB_PASS')) {
                $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4";
                $testConn = new PDO($dsn, DB_USER, DB_PASS, [
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
                ]);
                echo "<span class='success'>✓ Database connection successful!</span><br>";
                echo "• Host: " . DB_HOST . "<br>";
                echo "• Database: " . DB_NAME . "<br>";
                echo "• User: " . DB_USER . "<br>";
                
                // Check if tables exist
                $stmt = $testConn->query("SHOW TABLES");
                $tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
                echo "<br><strong>Tables found:</strong> " . count($tables) . "<br>";
                if (count($tables) < 5) {
                    echo "<span class='warning'>⚠ Database might not be fully installed</span>";
                    $warnings[] = "Few tables found in database";
                }
                
            } else {
                echo "<span class='error'>✗ Database constants not defined</span>";
                $errors[] = "Database configuration incomplete";
            }
        } catch (PDOException $e) {
            echo "<span class='error'>✗ Database connection failed:</span><br>";
            echo "<code>" . htmlspecialchars($e->getMessage()) . "</code>";
            $errors[] = "Database error: " . $e->getMessage();
        }
        echo "</div>";

        // 7. Composer/Vendor Check
        echo "<h2>7. Dependencies (Composer)</h2>";
        echo "<div class='check-item'>";
        $vendorAutoload = __DIR__ . '/vendor/autoload.php';
        if (file_exists($vendorAutoload)) {
            echo "<span class='success'>✓ Composer dependencies found</span><br>";
            echo "<code>vendor/autoload.php</code> exists";
            
            // Try to load it
            try {
                require_once $vendorAutoload;
                echo "<br><span class='success'>✓ Autoloader loaded successfully</span>";
            } catch (Exception $e) {
                echo "<br><span class='error'>✗ Autoloader error: " . htmlspecialchars($e->getMessage()) . "</span>";
                $errors[] = "Autoloader failed";
            }
        } else {
            echo "<span class='warning'>⚠ Composer vendor directory not found</span><br>";
            echo "Run <code>composer install</code> if you're using PhpSpreadsheet or TCPDF";
            $warnings[] = "Vendor directory missing";
        }
        echo "</div>";

        // 8. Server Information
        echo "<h2>8. Server Information</h2>";
        echo "<table>";
        echo "<tr><th>Variable</th><th>Value</th></tr>";
        $serverInfo = [
            'Server Software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown',
            'Document Root' => $_SERVER['DOCUMENT_ROOT'] ?? 'Unknown',
            'Script Filename' => $_SERVER['SCRIPT_FILENAME'] ?? 'Unknown',
            'PHP SAPI' => php_sapi_name(),
            'Max Execution Time' => ini_get('max_execution_time') . ' seconds',
            'Memory Limit' => ini_get('memory_limit'),
            'Upload Max Filesize' => ini_get('upload_max_filesize'),
            'Post Max Size' => ini_get('post_max_size'),
            'Timezone' => date_default_timezone_get()
        ];
        
        foreach ($serverInfo as $key => $value) {
            echo "<tr><td><strong>$key</strong></td><td><code>" . htmlspecialchars($value) . "</code></td></tr>";
        }
        echo "</table>";

        // 9. .htaccess Check
        echo "<h2>9. .htaccess File</h2>";
        echo "<div class='check-item'>";
        $htaccessFile = __DIR__ . '/.htaccess';
        if (file_exists($htaccessFile)) {
            echo "<span class='success'>✓ .htaccess file exists</span><br>";
            echo "<strong>Size:</strong> " . filesize($htaccessFile) . " bytes<br>";
            $htContent = file_get_contents($htaccessFile);
            if (strpos($htContent, 'RewriteEngine') !== false) {
                echo "<span class='info'>Contains rewrite rules - make sure mod_rewrite is enabled</span>";
            }
        } else {
            echo "<span class='warning'>⚠ No .htaccess file found</span>";
        }
        echo "</div>";

        // Summary
        echo "<h2>📊 Summary</h2>";
        
        if (empty($errors) && empty($warnings)) {
            echo "<div class='info' style='background: #D1FAE5; border-left-color: #10B981;'>";
            echo "<h3 style='margin-top: 0; color: #065F46;'>✓ All checks passed!</h3>";
            echo "<p>Your server environment appears to be properly configured. If you're still getting 500 errors, check:</p>";
            echo "<ul>";
            echo "<li>Server error logs (usually in /var/log/apache2/ or ~/logs/)</li>";
            echo "<li>Enable error display in config.php temporarily</li>";
            echo "<li>Check file ownership and permissions (should be www-data or your web server user)</li>";
            echo "</ul>";
            echo "</div>";
        } else {
            if (!empty($errors)) {
                echo "<div class='info' style='background: #FEE2E2; border-left-color: #EF4444;'>";
                echo "<h3 style='margin-top: 0; color: #991B1B;'>❌ Critical Errors Found:</h3>";
                echo "<ul>";
                foreach ($errors as $error) {
                    echo "<li>" . htmlspecialchars($error) . "</li>";
                }
                echo "</ul>";
                echo "<strong>These issues must be fixed before the application will work.</strong>";
                echo "</div>";
            }
            
            if (!empty($warnings)) {
                echo "<div class='info' style='background: #FEF3C7; border-left-color: #F59E0B;'>";
                echo "<h3 style='margin-top: 0; color: #92400E;'>⚠ Warnings:</h3>";
                echo "<ul>";
                foreach ($warnings as $warning) {
                    echo "<li>" . htmlspecialchars($warning) . "</li>";
                }
                echo "</ul>";
                echo "</div>";
            }
        }
        
        echo "<div class='info'>";
        echo "<h3 style='margin-top: 0;'>🔐 Security Note</h3>";
        echo "<p><strong>IMPORTANT:</strong> Delete this file (<code>server_check.php</code>) after troubleshooting! ";
        echo "It exposes sensitive server information.</p>";
        echo "</div>";
        ?>
    </div>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists