You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel项目启动报错:public/index.php不存在求助

克隆Laravel项目后php artisan serve启动失败问题

执行php artisan serve后终端报错:

php artisan serve
Starting Laravel development server: http://127.0.0.1:8000
[Sun Nov 27 08:38:27 2022] PHP 8.1.13 Development Server (http://127.0.0.1:8000) started
[Sun Nov 27 08:38:36 2022] 127.0.0.1:42986 Accepted
[Sun Nov 27 08:38:36 2022] PHP警告:require_once(/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php): Failed to open stream: No such file or directory in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21
[Sun Nov 27 08:38:36 2022] PHP致命错误:Uncaught Error: Failed opening required '/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php' (include_path='.:/usr/share/php') in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php:21
Stack trace:
#0 {main}
  thrown in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21
[Sun Nov 27 08:38:36 2022] 127.0.0.1:42986 Closing
[Sun Nov 27 08:38:36 2022] 127.0.0.1:42992 Accepted
[Sun Nov 27 08:38:36 2022] 127.0.0.1:43000 Accepted
[Sun Nov 27 08:38:47 2022] PHP警告:require_once(/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php): Failed to open stream: No such file or directory in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21
[Sun Nov 27 08:38:47 2022] PHP致命错误:Uncaught Error: Failed opening required '/home/almando/Documents/laravelPro/amazy-ecommerce/public/index.php' (include_path='.:/usr/share/php') in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php:21
Stack trace:
#0 {main}
  thrown in /home/almando/Documents/laravelPro/amazy-ecommerce/server.php on line 21

浏览器显示:

This page isn’t working
127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500

相关文件内容

bootstrap/app.php

<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

server.php

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

index.php

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists(__DIR__.'/storage/framework/maintenance.php')) {
    require __DIR__.'/storage/framework/maintenance.php';
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require __DIR__.'/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

$app = require_once __DIR__.'/bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);

解决步骤

  • 先确认项目根目录下的public/index.php是否存在:终端执行ls /home/almando/Documents/laravelPro/amazy-ecommerce/public查看文件列表,若缺失则重新克隆项目或从仓库手动下载该文件
  • 执行基础安装流程:
    1. 进入项目根目录:cd /home/almando/Documents/laravelPro/amazy-ecommerce
    2. 安装依赖:composer install(需提前安装Composer)
    3. 复制环境配置文件:cp .env.example .env
    4. 生成应用密钥:php artisan key:generate
  • 重新启动服务器:php artisan serve,访问http://127.0.0.1:8000测试

内容的提问来源于stack exchange,提问作者Hafenaaje

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 00:20:28