✏️ 编辑:setup.php
路径:
/home/boguraj1/.trash/public/setup.php
大小:8.49 KB · 修改:2026-07-23 16:13:46 · 权限:0644 · 可写
← 返回目录
👁 查看
⬇ 下载
<?php /** * TMITStore — One-Time Server Setup Script * ========================================= * cPanel-এ upload করার পর browser থেকে একবার run করো: * https://yourdomain.com/setup.php * * ⚠️ RUN করার পর এই ফাইলটি DELETE করো! */ // Secret token — অন্য কেউ যাতে run না করতে পারে $setupToken = 'tmit_setup_2024'; if (($_GET['token'] ?? '') !== $setupToken) { http_response_code(403); die('<h2>403 Forbidden</h2><p>Add ?token=tmit_setup_2024 to the URL to run setup.</p>'); } header('Content-Type: text/html; charset=UTF-8'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>TMITStore — Server Setup</title> <style> body { font-family: monospace; background: #1a1a2e; color: #eee; padding: 30px; } .box { background: #16213e; border-radius: 12px; padding: 30px; max-width: 700px; margin: 0 auto; } h2 { color: #e63946; } .ok { color: #4ade80; } .fail { color: #f87171; } .warn { color: #fbbf24; } .info { color: #60a5fa; } p { margin: 8px 0; font-size: 15px; } hr { border-color: #333; margin: 20px 0; } .done { background: #0f3460; border-radius: 8px; padding: 16px; margin-top: 20px; } </style> </head> <body> <div class="box"> <h2>⚙️ TMITStore Server Setup</h2> <hr> <?php // Auto-detect app root if (file_exists(__DIR__ . '/../vendor/autoload.php')) { $appRoot = realpath(__DIR__ . '/..'); $mode = 'local'; } elseif (file_exists(__DIR__ . '/../ecommerce/vendor/autoload.php')) { $appRoot = realpath(__DIR__ . '/../ecommerce'); $mode = 'cpanel'; } else { echo '<p class="fail">❌ Laravel application root not found!</p>'; echo '<p class="warn">Make sure the "ecommerce" folder is uploaded beside public_html.</p>'; exit; } echo "<p class='info'>📂 Mode: <strong>$mode</strong></p>"; echo "<p class='info'>📂 App Root: <strong>$appRoot</strong></p>"; // ── 1. Storage symlink ────────────────────────────────────────────────────── echo '<hr><p><strong>1. Storage Symlink</strong></p>'; $symlinkTarget = $appRoot . '/storage/app/public'; $symlinkPath = __DIR__ . '/storage'; if (is_link($symlinkPath)) { echo "<p class='ok'>✅ Storage symlink already exists.</p>"; } elseif (is_dir($symlinkPath)) { // A real folder exists — delete it first (safe on fresh installs) $deleted = true; $files = @scandir($symlinkPath); if ($files && count($files) > 2) { // Has files inside — don't auto-delete, warn instead echo "<p class='warn'>⚠️ /storage folder exists and has files. Delete it manually from File Manager then re-run setup.</p>"; $deleted = false; } else { @rmdir($symlinkPath); if (file_exists($symlinkPath)) { echo "<p class='fail'>❌ Could not delete existing /storage folder. Delete manually from cPanel File Manager.</p>"; $deleted = false; } else { echo "<p class='ok'>✅ Old empty /storage folder removed.</p>"; } } if ($deleted) { if (@symlink($symlinkTarget, $symlinkPath)) { echo "<p class='ok'>✅ Storage symlink created successfully.</p>"; } else { echo "<p class='fail'>❌ Symlink failed after folder removal.</p>"; echo "<p class='warn'>SSH: <code>ln -s $symlinkTarget $symlinkPath</code></p>"; } } } else { if (@symlink($symlinkTarget, $symlinkPath)) { echo "<p class='ok'>✅ Storage symlink created successfully.</p>"; } else { echo "<p class='fail'>❌ Could not create symlink automatically.</p>"; echo "<p class='warn'>SSH: <code>ln -s $symlinkTarget $symlinkPath</code></p>"; echo "<p class='warn'>Or ask your host to enable symlinks.</p>"; } } // ── 2. Storage directory permissions ─────────────────────────────────────── echo '<hr><p><strong>2. Storage Permissions</strong></p>'; $storageDirs = [ $appRoot . '/storage', $appRoot . '/storage/app', $appRoot . '/storage/app/public', $appRoot . '/storage/framework', $appRoot . '/storage/framework/cache', $appRoot . '/storage/framework/sessions', $appRoot . '/storage/framework/views', $appRoot . '/storage/logs', $appRoot . '/bootstrap/cache', ]; $allOk = true; foreach ($storageDirs as $dir) { if (!is_dir($dir)) { @mkdir($dir, 0775, true); } if (is_writable($dir)) { echo "<p class='ok'>✅ Writable: " . str_replace($appRoot, '', $dir) . "</p>"; } else { if (@chmod($dir, 0775)) { echo "<p class='ok'>✅ Fixed permissions: " . str_replace($appRoot, '', $dir) . "</p>"; } else { echo "<p class='fail'>❌ Not writable: " . str_replace($appRoot, '', $dir) . "</p>"; $allOk = false; } } } // ── 3. .env file check ────────────────────────────────────────────────────── echo '<hr><p><strong>3. Environment File</strong></p>'; if (file_exists($appRoot . '/.env')) { echo "<p class='ok'>✅ .env file found.</p>"; $envContent = file_get_contents($appRoot . '/.env'); if (str_contains($envContent, 'APP_ENV=production')) { echo "<p class='ok'>✅ APP_ENV=production</p>"; } else { echo "<p class='warn'>⚠️ APP_ENV is not set to production. Edit .env file.</p>"; } if (str_contains($envContent, 'APP_DEBUG=false')) { echo "<p class='ok'>✅ APP_DEBUG=false</p>"; } else { echo "<p class='warn'>⚠️ APP_DEBUG is not false. Set APP_DEBUG=false in .env!</p>"; } } else { echo "<p class='fail'>❌ .env file NOT found! Copy .env.production to .env and fill in your credentials.</p>"; } // ── 4. PHP version ────────────────────────────────────────────────────────── echo '<hr><p><strong>4. PHP Version</strong></p>'; $phpVer = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION; if (PHP_MAJOR_VERSION >= 8) { echo "<p class='ok'>✅ PHP $phpVer (required: 8.0+)</p>"; } else { echo "<p class='fail'>❌ PHP $phpVer — Need PHP 8.0 or higher!</p>"; } // ── 5. Required extensions ───────────────────────────────────────────────── echo '<hr><p><strong>5. PHP Extensions</strong></p>'; $required = ['pdo', 'pdo_mysql', 'mbstring', 'openssl', 'tokenizer', 'xml', 'ctype', 'json', 'bcmath', 'fileinfo', 'curl']; foreach ($required as $ext) { if (extension_loaded($ext)) { echo "<p class='ok'>✅ $ext</p>"; } else { echo "<p class='fail'>❌ $ext — Missing! Contact your host.</p>"; } } // ── 6. Clear License Cache ───────────────────────────────────────────────── echo '<hr><p><strong>6. License Cache</strong></p>'; $cacheDir = $appRoot . '/storage/framework/cache/data'; $cleared = 0; if (is_dir($cacheDir)) { $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($cacheDir, FilesystemIterator::SKIP_DOTS) ); foreach ($iter as $file) { if ($file->isFile()) { $content = @file_get_contents($file->getPathname()); // Only delete license-related cache files if ($content && (str_contains($content, '_tmit_lic'))) { @unlink($file->getPathname()); $cleared++; } } } } if ($cleared > 0) { echo "<p class='ok'>✅ License cache cleared ($cleared file removed).</p>"; } else { echo "<p class='info'>ℹ️ No license cache found (already clean).</p>"; } // ── Done ──────────────────────────────────────────────────────────────────── echo '<hr>'; echo '<div class="done">'; echo '<p class="ok" style="font-size:18px;font-weight:bold">✅ Setup Complete!</p>'; echo '<p class="warn">⚠️ <strong>DELETE this file immediately:</strong> <code>setup.php</code></p>'; echo '<p>Your site should now be live at your domain.</p>'; echo '</div>'; ?> </div> </body> </html>
💾 保存
取消
保存为 UTF-8,换行统一为 LF