
Laravel 项目在 cPanel 子域名下出现空白页,通常源于 index.php 中的路径引用错误、PHP 错误未显示或关键文件(如 vendor/autoload.php)加载失败;本文详解正确配置子域名文档根目录与入口文件路径的方法,并提供调试与验证步骤。
laravel 项目在 cpanel 子域名下出现空白页,通常源于 index.php 中的路径引用错误、php 错误未显示或关键文件(如 vendor/autoload.php)加载失败;本文详解正确配置子域名文档根目录与入口文件路径的方法,并提供调试与验证步骤。
在 cPanel 环境中将 Laravel 应用部署到子域名(如 ecommerce.ratul.info)时,常见误区是直接将整个 Laravel 项目(含 app/、bootstrap/、vendor/ 等)放在子域名的 Document Root(即 /public_html/ecommerce)下——这既不安全也不符合 Laravel 最佳实践。你当前的结构为:
/public_html/ecommerce/ ← 子域名实际指向的「Web 可访问根目录」(即 public 目录)
├── index.php ← 需手动修改此文件
├── .htaccess
└── flipmart/ ← 实际 Laravel 项目根目录(含 bootstrap/, vendor/, app/ 等)
├── bootstrap/
├── vendor/
├── app/
└── ...
该结构本身可行,但前提是 index.php 中的路径必须绝对准确且可被 PHP 正确解析。
✅ 正确的 index.php 路径配置如下(位于 /public_html/ecommerce/index.php):
<?php use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
// ✅ 确保路径基于当前 index.php 所在位置(即 /public_html/ecommerce)
require __DIR__.'/flipmart/vendor/autoload.php';
$app = require_once __DIR__.'/flipmart/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
⚠️ 关键注意事项:
- __DIR__ 指向 /public_html/ecommerce,因此 __DIR__.'/flipmart/vendor/autoload.php' 必须真实存在 —— 请通过 FTP 或 cPanel 文件管理器确认 /public_html/ecommerce/flipmart/vendor/autoload.php 文件存在且可读(权限建议 644,目录 755)。
- 若 vendor/ 不存在,请进入 /public_html/ecommerce/flipmart/ 目录,运行 composer install --no-dev(需服务器支持 CLI Composer);若不支持,需本地执行 composer install 后完整上传 vendor/。
- 开启 PHP 错误显示(否则空白页无任何提示):在 /public_html/ecommerce/index.php 顶部立即添加以下代码(放在
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
? 提示:也可在 cPanel 的 “PHP Selector” 或 .htaccess 中全局启用(如添加 php_flag display_errors on),但入口文件内强制设置最可靠。
- 检查 Laravel 环境配置:确保 /public_html/ecommerce/flipmart/.env 文件存在,且 APP_URL 设置为 https://ecommerce.ratul.info,APP_DEBUG=true(仅限开发环境,上线前务必设为 false)。
- 清除配置缓存(首次部署时尤其重要):若已通过 Artisan 访问,可临时在 /public_html/ecommerce/flipmart/ 下运行:
php artisan config:clear php artisan cache:clear
最后,验证 Web 服务器权限:Apache/Nginx 必须能读取 /public_html/ecommerce/flipmart/ 下的 storage/ 和 bootstrap/cache/ 目录。若报错 Permission denied,请执行(通过 SSH 或文件管理器):
chmod -R 755 /public_html/ecommerce/flipmart/storage chmod -R 755 /public_html/ecommerce/flipmart/bootstrap/cache
总结:子域名空白页本质是“静默失败”,核心破局点在于 显式暴露错误 + 精确校验路径 + 确保依赖就绪。按上述步骤逐项排查,90% 的子域部署白屏问题可快速定位并解决。











