require(vendor/autoload.php): 无法打开流

发布于 2025-01-13 19:01:02 字数 756 浏览 7 评论 0原文

我知道这个问题已经发布过很多次了,但对我来说这似乎是一个不同的问题。

确实,这个错误

警告:require(vendor/autoload.php):无法打开流:第 3 行的 C:\xampp\htdocs\site_web\send_mail.php 中没有此类文件或目录

致命错误:require():无法在第 3 行的 C:\xampp\htdocs\site_web\send_mail.php 中打开所需的“vendor/autoload.php”(include_path='C:\xampp\php\PEAR')

出现在我的代码的开头:

require 'vendor/autoload.php';

所以,我猜我的计算机中一定有一个 /vendor/autoload.php 文件(我已经安装了 Composer 并运行了 composer require phpmailer/phpmailer )。

因此,我在 Windows 命令行中使用:dir /s autoload.php 查找此文件,并在这里找到了一个:C:\Windows\SysWOW64\vendor\autoload.php,

但对我来说, syswow64 文件夹与 autoload.php 没有什么可看的,我不知道我在这里缺少什么。

I know that this issue has been posted many times, but for me it seems to be a different problem.

Indeed, this error

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\site_web\send_mail.php on line 3

Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\site_web\send_mail.php on line 3

appears at the begining of my code from this line:

require 'vendor/autoload.php';

So, I guess there must be a /vendor/autoload.php file somewhere in my computer (I have installed composer and ran composer require phpmailer/phpmailer).

So, I looked for this file using: dir /s autoload.php in the Windows command line, and found one here: C:\Windows\SysWOW64\vendor\autoload.php,

but for me, syswow64 folder has nothing to see with autoload.php, I don't see what I am missing here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

蒗幽 2025-01-20 19:01:02

您缺少的是运行composer install,它将导入您的包并创建供应商文件夹以及自动加载脚本。

确保您的相对路径正确。例如,PHPMailer 中的示例脚本位于项目根目录下的 examples/ 中,因此从那里加载 Composer 自动加载器的正确相对路径为 ../vendor/autoload.php< /代码>。

您在 C:\Windows\SysWOW64\vendor\autoload.php 中找到的 autoload.php 可能是一个全局 Composer 安装 - 您通常会在其中放置 phpcs、phpunit、phpmd 等内容。

composer update 与您相同,并且可能您想要使用的内容。如果您的代码使用当前的软件包版本进行了测试,则运行 update 可能会导致损坏,这可能需要进一步的工作和测试,因此除非有特定原因,否则不要运行 update并准确理解其含义。进一步澄清 - 您可能应该只在本地运行 composer update,而不是在服务器上,因为它很可能会破坏生产中的应用程序。

我经常看到有人抱怨人们无法使用 Composer,因为他们无法在服务器上运行它(例如,因为它是共享的并且他们没有 shell 访问权限)。在这种情况下,您仍然可以使用 Composer:在本地运行它(没有此类限制的环境),然后上传它生成的本地供应商文件夹以及所有其他 PHP 脚本。

运行 composer update 还会执行 composer 安装,并且如果您当前没有 vendor 文件夹(正常情况下你有一个项目的新检出),然后它会创建一个,并覆盖你已有的任何 composer.lock 文件,更新其中标记的包版本,这就是潜在的危险。

同样,如果您当前没有 composer.lock 文件(例如,如果它未提交到项目中),则 composer install 也会有效地执行 composer更新。因此,了解两者之间的差异至关重要,因为它们绝对不可互换。

还可以通过命名来更新单个包,例如:

composer update ramsey/uuid

这将重新解析您的 composer.json 中指定的版本并将其安装在您的供应商文件夹中,并更新您的 要匹配的composer.lock 文件。如果您只需要对一个软件包进行特定更新,那么与一般 composer 更新 相比,这引起问题的可能性要小得多。

包含自己的composer.lock文件是正常的;由应用程序来修复版本,而不是它们使用的库。因此,库开发人员需要保持与应用程序开发人员所需的更广泛主机环境的兼容性。例如,一个库可能与 Laravel 5、6、7 和 8 兼容,但使用它的应用程序可能因其他原因需要 Laravel 8。

Composer 2.0 消除了安装和更新结果之间剩余的不一致之处;如果您运行的是 Composer 1.x,您绝对应该升级

What you're missing is running composer install, which will import your packages and create the vendor folder, along with the autoload script.

Make sure your relative path is correct. For example the example scripts in PHPMailer are in examples/, below the project root, so the correct relative path to load the composer autoloader from there would be ../vendor/autoload.php.

The autoload.php you found in C:\Windows\SysWOW64\vendor\autoload.php is probably a global composer installation – where you'll usually put things like phpcs, phpunit, phpmd etc.

composer update is not the same thing, and probably not what you want to use. If your code is tested with your current package versions then running update may cause breakages which may require further work and testing, so don't run update unless you have a specific reason to and understand exactly what it means. To clarify further – you should probably only ever run composer update locally, never on your server as it is reasonably likely to break apps in production.

I often see complaints that people can't use composer because they can't run it on their server (e.g. because it's shared and they have no shell access). In that case, you can still use composer: run it locally (an environment that has no such restrictions), and upload the local vendor folder it generates along with all your other PHP scripts.

Running composer update also performs a composer install, and if you do not currently have a vendor folder (normal if you have a fresh checkout of a project), then it will create one, and also overwrite any composer.lock file you already have, updating package versions tagged in it, and this is what is potentially dangerous.

Similarly, if you do not currently have a composer.lock file (e.g. if it was not committed to the project), then composer install also effectively performs a composer update. It's thus vital to understand the difference between the two as they are definitely not interchangeable.

It is also possible to update a single package by naming it, for example:

composer update ramsey/uuid

This will re-resolve the version specified in your composer.json and install it in your vendor folder, and update your composer.lock file to match. This is far less likely to cause problems than a general composer update if you just need a specific update to one package.

It is normal for libraries to not include a composer.lock file of their own; it's up to apps to fix versions, not the libraries they use. As a result, library developers are expected to maintain compatibility with a wider range of host environments than app developers need to. For example, a library might be compatible with Laravel 5, 6, 7, and 8, but an app using it might require Laravel 8 for other reasons.

Composer 2.0 removed any remaining inconsistencies between install and update results; if you're running composer 1.x you should definitely upgrade.

明媚殇 2025-01-20 19:01:02

如果您在运行时也遇到错误,

composer install

请先运行此命令

composer dump-autoload

此命令将清理所有已编译的文件及其路径。

If you get the error also when you run

composer install

Just run this command first

composer dump-autoload

This command will clean up all compiled files and their paths.

冷血 2025-01-20 19:01:02

@Bashir 几乎帮助了我,但我需要:

composer update --no-scripts

显然这可以防止在执行 artisan 之前包含任何脚本。

我在页面的中间找到了答案:
https://laracasts.com/discuss/channels/general-discussion/fatal-error-class-Illuminatefoundationapplication-not-found-in-pathtoprojectbootstrapappphp-on-line-14?page=0

@Bashir almost helped me but I needed:

composer update --no-scripts

Apparently this prevents any scripts from being included before executing artisan.

I found the answer here half-way down the page:
https://laracasts.com/discuss/channels/general-discussion/fatal-error-class-illuminatefoundationapplication-not-found-in-pathtoprojectbootstrapappphp-on-line-14?page=0

金橙橙 2025-01-20 19:01:02

正确的 autoload.php 配置:

A) 快速回答

您的 autoload.php 路径错误。 IE。 C:\Windows\SysWOW64\vendor\autoload.php
迄今为止:您需要将其更改为:C:\Users\\vendor\autoload.php


B) 示例步骤:
我们将采用 facebook/php-graph-以sdk为例;根据需要更改为包名称

  1. 安装 composer.exe
  2. 打开 CMD 提示符。 + R + 输入 CMD
  3. 运行此命令: composer require facebook/graph-sdk
  4. 在 PHP 页面中包含路径: require_once 'C:\Users\\vendor\autoload.php';
  5. 为您的包定义配置 SecretsAccess Token...等。
  6. 快乐编码。

C) 更多详细信息:

在 Windows 上安装 Composer 将为您的包设置此默认路径;您可以在那里找到它们并包含自动加载器路径:

C:\Users\<Windows User Name>\vendor

对于您提出的同一问题;答案是WAMP Server 64 BIT for Windows的路径。

然后只需在您的 PHP 应用程序中将其更改

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

require_once 'C:\Users\<Windows User Name>\vendor\autoload.php'; 

C:\Users\ 下找到您的 Windows 用户名

在这一切之前,如 B) 中之前指出的,您需要运行以下命令:

composer require <package name>

对于 facebook php SDK为了例如:

composer require facebook/graph-sdk

感谢您提出这个问题;非常感谢,因为它帮助我解决了类似的问题并结束了这个简单的教程的编写。

Proper autoload.php configuration:

A) Quick answer:

Your autoload.php path is wrong. ie. C:\Windows\SysWOW64\vendor\autoload.php
To date: you need to change it to: C:\Users\<Windows User Name>\vendor\autoload.php


B) Steps with example:
We will take facebook/php-graph-sdk as an example; change to Package Name as needed.

  1. Install composer.exe
  2. Open CMD Prompt. + R + type CMD
  3. Run This command: composer require facebook/graph-sdk
  4. Include path in your PHP page: require_once 'C:\Users\<Windows User Name>\vendor\autoload.php';
  5. Define configuration Secrets and Access Token for your package...etc.
  6. Happy codinig.

C) Further details:

Installing composer on windows will set this default path for your pacakges; you can find them there and include the autoloader path:

C:\Users\<Windows User Name>\vendor

For the same question you asked; the answer was this path for WAMP Server 64 BIT for Windows.

Then simply in your PHP Application change this:

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

To:

require_once 'C:\Users\<Windows User Name>\vendor\autoload.php'; 

Find your windows username under C:\Users\

Before all this, as pointed before in B) , you need to run this command:

composer require <package name>

for facebook php SDK for example:

composer require facebook/graph-sdk

Thank you for asking this question; appreciated as it helped me fix similar issue and ended writing this simple tutorial.

南冥有猫 2025-01-20 19:01:02

首先确保您已经安装了作曲家。

composer install

如果您已经安装,请更新作曲家。

composer update

First make sure you have installed the composer.

composer install

If you already have installed then update the composer.

composer update
梦旅人picnic 2025-01-20 19:01:02

首先,检查 index.php 内的路由,

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

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

在我的情况下,该路由不起作用,我必须检查目录。

First, review route inside index.php

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

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

in my case the route did not work, I had to review the directories.

酷炫老祖宗 2025-01-20 19:01:02

如果您从 Github 克隆项目或从其他地方获取项目,您将遇到此错误。那是因为您缺少供应商文件夹和其他文件。 供应商文件夹包含依赖于您的项目的包。包依赖项存储在 composer.json 文件中,并且在推送到 Github排除该文件夹。

只需运行以下命令即可修复此错误:

composer install

然后您将获得项目所需的所有资源。

If you have cloned your project from Github or got it from somewhere else, you will encounter this error. That's because you are missing the vendor folder and other files. The vendor folder contains packages which are dependent to your project. The package dependencies are stored in composer.json file and the folder was excluded while pushing to Github.

Fix this error by simply running:

composer install

Then you will get all the assets needed for your project.

无名指的心愿 2025-01-20 19:01:02

为我
只需先运行此命令

composer dump-autoload

即可添加供应商文件夹。

然后运行此命令

composer update --no-scripts

来更新composer。

For me
Just run this command first

composer dump-autoload

to add vendor folder.

then run this command

composer update --no-scripts

to update composer.

多情癖 2025-01-20 19:01:02

使用 ex 所需的库创建composer.json 文件:

{
    "require": {
        "mpdf/mpdf": "^6.1"
    }
}

在存在composer.json 的位置执行以下命令:

composer install

如果是 Drupal:

使用 drupal 的 Web 根文件夹来包含 ex 的自动加载:

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/vendor/autoload.php';

如果是其他系统:
使用根文件夹变量或位置来包含 autoload.php

Create composer.json file with requisite library for ex:

{
    "require": {
        "mpdf/mpdf": "^6.1"
    }
}

Execute the below command where composer.json exists:

composer install

In case of Drupal :

Use the web root folder of drupal to include autoload for ex:

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/vendor/autoload.php';

In case of other systems:
Use the root folder variable or location to include the autoload.php

伴我老 2025-01-20 19:01:02

运行composer更新。就是这样

run composer update. That's it

亣腦蒛氧 2025-01-20 19:01:02

我的机器中有这条路径:

C:/xampp5.0/htdocs/project-recordando-symfony/project-recordando-symfony

然后我运行了 composer install 或/和 composer update 并返回了此错误:

ErrorException ZipArchive::extractTo...

该错误是因为您的路径太长,我更改为:

C:/xampp5.0/htdocs/p-symfony/*

并且有效!

I had this path in my machine:

C:/xampp5.0/htdocs/project-recordando-symfony/project-recordando-symfony

Then I ran composer install or/and composer update and it returned this error:

ErrorException ZipArchive::extractTo...

That error is because your path is too much long, I changed to:

C:/xampp5.0/htdocs/p-symfony/*

and worked!

镜花水月 2025-01-20 19:01:02

您只是缺少项目中的 composer 安装

创建 Laravel 项目后,打开终端并输入:

composer install

You're just missing the composer install on your project.

After you created your laravel project, open the terminal and type:

composer install
海之角 2025-01-20 19:01:02

我能够通过删除作曲家并以正确的方式重新安装来解决。这就是我所做的:

然后我才能让 Composer 安装再次工作。在此问题的底部找到了我的答案: https://github.com/composer/composer/问题/5510

I was able to resolve by removing composer and reinstalling the proper way. Here is what I did:

I was then able to get composer install to work again. Found my answer at the bottom of this issue: https://github.com/composer/composer/issues/5510

多孤肩上扛 2025-01-20 19:01:02

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

警告:require(vendor/autoload.php):无法打开流:没有这样的文件或目录

当您通过git下载项目时,下载的项目没有vendor文件夹

你需要 /vendor 因为你所有的包都在那里,包括 Laravel 使用的所有类。供应商目录包含您的 Composer 依赖项。

解决方案很简单,只需运行此命令:

composer update --no-scripts 
composer update
  • composer update --no-scripts 它将跳过执行 composer 中定义的脚本.json 文件。
  • composer update 它将更新您在 composer.json 文件中指定的依赖项。

使用此命令,您将在项目中重新创建 vendor 文件夹,之后您的项目将开始正常工作。

In your project folder, the vendor folder is missing so you got this error:

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

When you download the project through git, the project is downloaded without the vendor folder

You need /vendor because all your packages are there, including all the classes Laravel uses. The vendor directory contains your Composer dependencies.

The solution is simple, Just run this command:

composer update --no-scripts 
composer update
  • composer update --no-scripts It will Skips execution of scripts defined in composer.json file.
  • composer update It will update your depencencies as they are specified in composer.json file.

With this command, you will re-create the vendor folder in your project and after that your project will start working normally.

贱人配狗天长地久 2025-01-20 19:01:02

出现此错误是因为缺少一些文件,主要原因是“Composer

“在此处输入图像描述”"

首先在 CMD 中运行这些命令

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

然后
创建一个新项目
示例:

D:/Laravel_Projects/New_Project
laravel new New_Project

之后使用启动服务器

php artisan serve

This error occurs because of missing some files and the main reason is "Composer"

enter image description here

First Run these commands in CMD

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Then
Create a New project
Example:

D:/Laravel_Projects/New_Project
laravel new New_Project

After that start the server using

php artisan serve
你另情深 2025-01-20 19:01:02

就我而言,这是由于该项目未完全安装,因为我的硬盘上没有足够的空间

In my case, It was due to the non-fully installation of the project, because I didn't have enough space on my hard disk

一指流沙 2025-01-20 19:01:02

如果您有克隆存储库并尝试在发生此类错误时进行设置,则根目录中需要有一个名为“vendor”的目录。

“.gitingore”文件已编写代码以不包含 GIT 上的供应商目录,因此在克隆 GIT 后,您的项目将面临缺少供应商目录的问题。

添加供应商目录后,您的项目将再次开始工作。

There will be a directory called "vendor" that needs to be in your root directory if you have a cloned repository and trying to set up that time this type of error occurring.

".gitingore" file has written code to not include vendor directory on GIT so after cloning GIT your project facing the issue of missing vendor directory.

Once you add vendor directory your project will start working again.

浮生未歇 2025-01-20 19:01:02

要解决 autoload.php 错误,请按照下列步骤操作:

1.运行 Composer Install:

  • 导航到您的项目目录。
  • 运行 composer install 以创建 vendor 文件夹和自动加载脚本。

2.验证相对路径:

  • 确保脚本中 autoload.php 的路径正确。为了
    例如,如果您的脚本位于子目录中,请使用
    ../vendor/autoload.php.

3.避免 Composer 更新:

  • 除非必要,否则不要运行 composer 更新,因为这可能会导致
    依赖性问题。使用composer install来避免重大更改。

4. Global Composer 安装:

  • 如果您在全局目录中找到 autoload.php(例如,
    C:\Windows\SysWOW64\vendor\autoload.php),它是全局的一部分
    作曲家设置。确保您使用正确的本地项目路径。

5.本地环境设置:

如果您无法在服务器上运行 Composer,请在本地运行它并将供应商文件夹上传到您的服务器。

6.更新特定包:

要更新单个包而不影响其他包,请使用:

composer update package/name

To resolve the autoload.php error, follow these steps:

1. Run Composer Install:

  • Navigate to your project directory.
  • Run composer install to create the vendor folder and the autoload script.

2. Verify Relative Path:

  • Ensure the path to autoload.php is correct in your scripts. For
    example, if your scripts are in a subdirectory, use
    ../vendor/autoload.php.

3. Avoid Composer Update:

  • Do not run composer update unless necessary, as it can cause
    dependency issues. Use composer install to avoid breaking changes.

4. Global Composer Installation:

  • If you find autoload.php in a global directory (e.g.,
    C:\Windows\SysWOW64\vendor\autoload.php), it is part of a global
    Composer setup. Ensure you are using the correct local project path.

5. Local Environment Setup:

If you cannot run Composer on your server, run it locally and upload the vendor folder to your server.

6. Update Specific Packages:

To update a single package without affecting others, use:

composer update package/name
遗忘曾经 2025-01-20 19:01:02

更改 php.ini 上的 auto_prepend_file 属性

; Automatically add files before PHP document. 
;http://php.net/auto-prepend-file 
auto_prepend_file =

Change the auto_prepend_file property on php.ini

; Automatically add files before PHP document. 
;http://php.net/auto-prepend-file 
auto_prepend_file =
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文