首页 > 解决方案 > 在本地主机上运行 php artisan serve 命令时出错

问题描述

我遇到了php artisan serve命令问题。我正在处理一个 Laravel 项目,当我从浏览器访问该文件夹时,它工作正常,但是当我运行php artisan serve命令时,它向我显示以下错误:

警告:需要(E:\xampp\htdocs\www\LFS\public../vendor/autoload.php):无法打开流:E:\xampp\htdocs\www\LFS\public\ 中没有这样的文件或目录第 24 行的 index.php

致命错误:require():在 E:\ xampp\htdocs\www\LFS\public\index.php 第 24 行

我是 Laravel 的新手,请让我知道我哪里出错了。

我检查了以下public/index.php文件中的代码是我的代码。我想一切都很好,我只是将相同的index.php文件复制粘贴到我的根文件夹中。

<?php

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

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

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

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

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

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

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

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

我希望可以从浏览器直接访问该项目,并且还应该在php artisan serve命令上运行。

标签: laravellaravel-artisanserve

解决方案


在您的项目文件夹中,缺少供应商文件夹,因此您收到此错误:

警告:需要(E:\xampp\htdocs\www\LFS\public../vendor/autoload.php):无法打开流:没有这样的文件或目录

只需运行以下命令:

composer update --no-scripts 
composer update

使用此命令,您将在项目中重新创建供应商文件夹


推荐阅读