【问题标题】:Error while running php artisan serve command on localhost在本地主机上运行 php artisan serve 命令时出错
【发布时间】:2019-11-28 03:09:47
【问题描述】:

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

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

致命错误:require(): 无法打开所需的 'E:\xampp\htdocs\www\LFS\public../vendor/autoload.php' (include_path='E:\xampp\php\PEAR') 在 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 命令上运行。

【问题讨论】:

  • 你运行 composer install 了吗?如果您想使用 php artisan serve 来启动服务器(以防万一您不知道),也无需将项目放入您的 htdocs 文件夹中。并且不要在某处复制粘贴任何 index.php 文件。 laravel“根”文件夹是公用文件夹而不是项目根目录。
  • 默认情况下,serve 命令使用端口 8000,您应该通过 localhost:8000 访问您的网站。但是,如果您想使用默认的 http 端口,请使用命令 php artisan serve --port 80
  • 是的,我使用了 composer install 命令,它安装了所有软件包,实际上我正在使用 pusher 构建聊天系统,并且我也在使用 Vue js,但是当我在 bootstrap.js 中打开我的控制台时文件我有同样的错误。因此,我猜我的聊天系统无法实时工作。否则,一切都很好,但我需要重新加载页面以获取新消息。

标签: laravel laravel-artisan serve


【解决方案1】:

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

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

只需运行以下命令:

composer update --no-scripts 
composer update

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

【讨论】:

  • 我的项目中有供应商文件夹,我之前运行过 composer update 命令,它会在我的项目根目录上创建一个供应商文件夹。
猜你喜欢
  • 1970-01-01
  • 2021-07-02
  • 1970-01-01
  • 2019-02-03
  • 2017-05-31
  • 2021-05-27
  • 2020-05-29
  • 2018-01-31
  • 1970-01-01
相关资源
最近更新 更多