php 警告:要求(...):无法打开流:中没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26811134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:04:03  来源:igfitidea点击:

Warning: require(...): failed to open stream: No such file or directory in

phplaravelrequire

提问by Lovelock

just moved over my laravel site to my live server and straight away faced with this error.

刚刚将我的 Laravel 站点移至我的实时服务器,并立即面临此错误。

The complete error is:

完整的错误是:

Warning: require(/var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/autoload.php on line 17

Fatal error: require(): Failed opening required '/var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/sites/b/beta.buildsanctuary.com/public_html/local/bootstrap/autoload.php on line 17

The line 17 is:

第 17 行是:

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

需要目录.'/../vendor/autoload.php';

Folder structure is:

文件夹结构为:

beta.buildsanctuary.com
  -- public_html
  -- subdomains
    -- beta
      -- local
        -- bootstrap
        -- vendor

Any help where this is going wrong? And how to fix? Pulling my hair out trying all sorts of paths.

这哪里出错了有什么帮助吗?以及如何修复?尝试各种路径拉我的头发。

Thanks, Craig.

谢谢,克雷格。

回答by Chris54721

As you can see from the error, PHP is looking for

从错误中可以看出,PHP正在寻找

public_html/local/bootstrap/../vendor/autoload.php`

which is

这是

public_html/local/vendor/autoload.php

That folder does not exist. I think the folder structure you posted is wrong.

该文件夹不存在。我认为您发布的文件夹结构是错误的。

Anyway, try this:

无论如何,试试这个:

require('../vendor/autoload.php');

回答by Arón Vargas Hernández

I've had the same problem and it was that Composer was not installed yet in the server, so the directories structure it creates on your project does not exist neither.

我遇到了同样的问题,因为 Composer 尚未安装在服务器中,因此它在您的项目中创建的目录结构也不存在。

First you have to install composer on your server, follow the instructions for your system given at the composer project webpage, https://getcomposer.org/.

首先,您必须在您的服务器上安装 composer,按照 composer 项目网页https://getcomposer.org/ 上给出的系统说明进行操作。

Next you have to go in a terminal or cmd to the base folder of your project.

接下来,您必须在终端或 cmd 中进入项目的基本文件夹。

There you can use the commandline composer init, wich will guide you to create your composer.json file into your project.

在那里你可以使用命令行 composer init,它会指导你在你的项目中创建你的 composer.json 文件。

Once you have created your composer.json file, you have to execute the commandline composer install.

创建 composer.json 文件后,您必须执行命令行 composer install。

This commandline will create all the dependencies you have written on your composer.json, and also will create the folder structure so the code you require would find the proper path.

此命令行将创建您在 composer.json 上编写的所有依赖项,还将创建文件夹结构,以便您需要的代码找到正确的路径。

At last, you have to reference the redirection to the folder vendor depending on the current folder structure location of your php file.

最后,您必须根据 php 文件的当前文件夹结构位置将重定向引用到文件夹供应商。

If you look for information, http://www.phptherightway.com/was really helpfull.

如果您查找信息,http://www.phptherightway.com/ 真的很有帮助。

回答by dmSherazi

I strongly believe that a corrupted cache was the cause, I cannot be 100% sure but it seem that it is likely the culprit.

我坚信缓存损坏是原因,我不能 100% 确定,但似乎它可能是罪魁祸首。

So, if anyone comes across a similar problem, I would suggest the following steps:

所以,如果有人遇到类似的问题,我会建议以下步骤:

  1. Delete the vendor folder
  2. Delete composer.lock
  3. Run the command composer clearcache (or clear-cache)
  4. Run composer install
  1. 删除供应商文件夹
  2. 删除 composer.lock
  3. 运行命令 composer clearcache (或 clear-cache)
  4. 运行作曲家安装

I hope this can help somebody.

我希望这可以帮助某人。

回答by Mohammad Selim Miah

Just run the following command, it will automatically install necessary dependencies:

只需运行以下命令,它就会自动安装必要的依赖项:

composer install

作曲家安装

回答by Caliari

I had the same problem when I have had migrated a drupal website to new server... To solve the problem I just used the composer command:

当我将一个 Drupal 网站迁移到新服务器时,我遇到了同样的问题......为了解决这个问题,我只是使用了 composer 命令:

  1. First cd into website directory, EX: cd /var/www/your_website

  2. Run composer to install drupal 8 dependencies that it's need in the website directory;

  1. 首先cd进入网站目录,EX: cd /var/www/your_website

  2. 运行 composer 在网站目录中安装它需要的 drupal 8 依赖项;

composer install

composer install

If you use the sudo command, make sure the .../vendordirectory has the right permission to be accessed by the user who in the /var/wwwdirectory;

如果使用 sudo 命令,请确保该.../vendor目录具有该目录中的用户可以访问的正确权限/var/www

sudo composer install

sudo composer install

This basically will solve the .../public_html/autoload.php on line 14issue!

这样基本上就可以解决.../public_html/autoload.php on line 14问题了!