GitGram — check.php — GitGram
Hobbes_OS2_Archive / main / v1.15 / check.php3,689 B↓ Raw
<?php
// Hobbes environment diagnostic - DELETE THIS FILE after setup is confirmed working
// Access directly: http://hobbes.os-2.in/check.php

$checks = [];

// PHP version
$checks['PHP Version'] = PHP_VERSION . ' (' . (PHP_VERSION_ID >= 80400 ? 'OK' : 'Needs 8.x+') . ')';

// mod_rewrite detection (approximate - Apache exposes this via SERVER_SOFTWARE or env)
$rewrite_loaded = function_exists('apache_get_modules')
    ? (in_array('mod_rewrite', apache_get_modules()) ? 'YES (confirmed)' : 'NOT found in apache_get_modules()')
    : 'Unknown — apache_get_modules() not available (likely PHP-FPM or CGI)';
$checks['mod_rewrite'] = $rewrite_loaded;

// SCRIPT_FILENAME vs DOCUMENT_ROOT — shows where PHP thinks the root is
$checks['DOCUMENT_ROOT']    = $_SERVER['DOCUMENT_ROOT']    ?? 'not set';
$checks['SCRIPT_FILENAME']  = $_SERVER['SCRIPT_FILENAME']  ?? 'not set';
$checks['REQUEST_URI']      = $_SERVER['REQUEST_URI']       ?? 'not set';
$checks['SERVER_SOFTWARE']  = $_SERVER['SERVER_SOFTWARE']   ?? 'not set';

// PHP handler type
$checks['PHP SAPI'] = PHP_SAPI; // 'apache2handler' = mod_php, 'fpm-fcgi' = PHP-FPM, 'cgi-fcgi' = CGI

// .htaccess readable test — write a known value and read it back via ini_get
$checks['upload_max_filesize'] = ini_get('upload_max_filesize') . ' (want 200M — if showing default, .user.ini not applied yet or php_value blocked)';
$checks['memory_limit']        = ini_get('memory_limit');

// data directory web-accessible check
$data_htaccess = __DIR__ . '/data/.htaccess';
$checks['data/.htaccess exists'] = file_exists($data_htaccess) ? 'YES' : 'MISSING — data directory is UNPROTECTED';

// Writable checks
foreach (['data/users', 'data/files', 'data/uploads', 'data/pool', 'data/settings', 'data/invites', 'data/index', 'data/categories'] as $dir) {
    $path = __DIR__ . '/' . $dir;
    $checks['writable: ' . $dir] = is_writable($path) ? 'YES' : 'NO — chmod 755 or 775 required';
}

// index.php exists
$checks['index.php exists'] = file_exists(__DIR__ . '/index.php') ? 'YES' : 'MISSING';

// RewriteBase guess
$script = $_SERVER['SCRIPT_NAME'] ?? '/check.php';
$base   = rtrim(dirname($script), '/');
$checks['Detected RewriteBase'] = ($base === '' ? '/' : $base) . ' (use this in .htaccess if site is in a subdirectory)';

?><!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>Hobbes Diagnostic</title>
<style>body{font-family:monospace;font-size:13px;background:#c0c0c0;padding:20px}
table{border-collapse:collapse;background:#fff;width:100%;max-width:900px}
th{background:#000080;color:#fff;padding:4px 10px;text-align:left}
td{padding:3px 10px;border-bottom:1px solid #ccc}
tr:nth-child(even)td{background:#eee}
.ok{color:green}.warn{color:orange}.bad{color:red}
h2{color:#000080}</style></head>
<body>
<h2>Hobbes OS/2 Archive &mdash; Environment Check</h2>
<p><strong>Delete <code>check.php</code> after confirming setup works.</strong></p>
<table>
<tr><th>Check</th><th>Result</th></tr>
<?php foreach ($checks as $label => $value): ?>
<tr><td><?php echo htmlspecialchars($label); ?></td>
    <td><?php echo htmlspecialchars($value); ?></td></tr>
<?php endforeach; ?>
</table>

<h2>mod_rewrite test</h2>
<p>If mod_rewrite is working, this link should load the home page (not a 404):</p>
<p><a href="/">/</a> &mdash; <a href="/setup">/setup</a> &mdash; <a href="/browse">/browse</a></p>

<h2>Direct PHP access (no rewrite needed)</h2>
<p>These always work regardless of mod_rewrite:</p>
<p><a href="/index.php">/index.php</a> &mdash; <a href="/index.php?_r=setup">/index.php?_r=setup</a></p>

<h2>Next step</h2>
<p>Share the output of this page if the 404 persists and mod_rewrite status is shown.</p>
</body></html>
Ready
GitGram