require(vendor/autoload.php): 无法打开流
我知道这个问题已经发布过很多次了,但对我来说这似乎是一个不同的问题。
确实,这个错误
警告: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
您缺少的是运行
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.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 runningupdate
may cause breakages which may require further work and testing, so don't runupdate
unless you have a specific reason to and understand exactly what it means. To clarify further – you should probably only ever runcomposer 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 acomposer install
, and if you do not currently have avendor
folder (normal if you have a fresh checkout of a project), then it will create one, and also overwrite anycomposer.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), thencomposer install
also effectively performs acomposer 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:
This will re-resolve the version specified in your
composer.json
and install it in your vendor folder, and update yourcomposer.lock
file to match. This is far less likely to cause problems than a generalcomposer 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.
如果您在运行时也遇到错误,
请先运行此命令
此命令将清理所有已编译的文件及其路径。
If you get the error also when you run
Just run this command first
This command will clean up all compiled files and their paths.
@Bashir 几乎帮助了我,但我需要:
显然这可以防止在执行 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:
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
正确的
autoload.php
配置:A) 快速回答:
您的 autoload.php 路径错误。 IE。
C:\Windows\SysWOW64\vendor\autoload.php
迄今为止:您需要将其更改为:
C:\Users\\vendor\autoload.php
B) 示例步骤:
我们将采用 facebook/php-graph-以sdk为例;根据需要更改为
包名称
。CMD
composer require facebook/graph-sdk
require_once 'C:\Users\\vendor\autoload.php';
Secrets
和Access Token
...等。C) 更多详细信息:
在 Windows 上安装 Composer 将为您的包设置此默认路径;您可以在那里找到它们并包含自动加载器路径:
对于您提出的同一问题;答案是WAMP Server 64 BIT for Windows的路径。
然后只需在您的 PHP 应用程序中将其更改
为
: 在
C:\Users\
下找到您的 Windows 用户名在这一切之前,如 B) 中之前指出的,您需要运行以下命令:
对于 facebook php 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.CMD
composer require facebook/graph-sdk
require_once 'C:\Users\<Windows User Name>\vendor\autoload.php';
Secrets
andAccess Token
for your package...etc.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:
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:
To:
Find your windows username under
C:\Users\
Before all this, as pointed before in B) , you need to run this command:
for facebook php SDK for example:
Thank you for asking this question; appreciated as it helped me fix similar issue and ended writing this simple tutorial.
首先确保您已经安装了作曲家。
如果您已经安装,请更新作曲家。
First make sure you have installed the composer.
If you already have installed then update the composer.
首先,检查 index.php 内的路由,
在我的情况下,该路由不起作用,我必须检查目录。
First, review route inside index.php
in my case the route did not work, I had to review the directories.
如果您从 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.
为我
只需先运行此命令
即可添加供应商文件夹。
然后运行此命令
来更新composer。
For me
Just run this command first
to add vendor folder.
then run this command
to update composer.
使用 ex 所需的库创建composer.json 文件:
在存在composer.json 的位置执行以下命令:
如果是 Drupal:
使用 drupal 的 Web 根文件夹来包含 ex 的自动加载:
如果是其他系统:
使用根文件夹变量或位置来包含 autoload.php
Create composer.json file with requisite library for ex:
Execute the below command where composer.json exists:
In case of Drupal :
Use the web root folder of drupal to include autoload for ex:
In case of other systems:
Use the root folder variable or location to include the autoload.php
运行
composer更新
。就是这样run
composer update
. That's it我的机器中有这条路径:
然后我运行了 composer install 或/和 composer update 并返回了此错误:
该错误是因为您的路径太长,我更改为:
并且有效!
I had this path in my machine:
Then I ran
composer install
or/andcomposer update
and it returned this error:That error is because your path is too much long, I changed to:
and worked!
您只是缺少项目中的
composer 安装
。创建 Laravel 项目后,打开终端并输入:
You're just missing the
composer install
on your project.After you created your laravel project, open the terminal and type:
我能够通过删除作曲家并以正确的方式重新安装来解决。这就是我所做的:
下载地址:https://getcomposer.org/installer
全局安装: mv Composer.phar /usr/local/bin/composer
(注意:我必须将我的移动到 mv Composer.phar /usr/bin/composer)
然后我才能让 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:
Download from: https://getcomposer.org/installer
global install: mv composer.phar /usr/local/bin/composer
(Note: I had to move mine to mv composer.phar /usr/bin/composer)
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
在您的项目文件夹中,供应商文件夹丢失,因此您收到此错误:
当您通过git下载项目时,下载的项目没有vendor文件夹
你需要
/vendor
因为你所有的包都在那里,包括 Laravel 使用的所有类。供应商目录包含您的 Composer 依赖项。解决方案很简单,只需运行此命令:
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:
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
It will Skips execution of scripts defined incomposer.json
file.composer update
It will update your depencencies as they are specified incomposer.json
file.With this command, you will re-create the vendor folder in your project and after that your project will start working normally.
出现此错误是因为缺少一些文件,主要原因是“Composer”
首先在 CMD 中运行这些命令
然后
创建一个新项目
示例:
之后使用启动服务器
This error occurs because of missing some files and the main reason is "Composer"
First Run these commands in CMD
Then
Create a New project
Example:
After that start the server using
就我而言,这是由于该项目未完全安装,因为我的硬盘上没有足够的空间
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
如果您有克隆存储库并尝试在发生此类错误时进行设置,则根目录中需要有一个名为“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.
要解决 autoload.php 错误,请按照下列步骤操作:
1.运行 Composer Install:
composer install
以创建vendor
文件夹和自动加载脚本。2.验证相对路径:
例如,如果您的脚本位于子目录中,请使用
../vendor/autoload.php.
3.避免 Composer 更新:
依赖性问题。使用composer install来避免重大更改。
4. Global Composer 安装:
C:\Windows\SysWOW64\vendor\autoload.php),它是全局的一部分
作曲家设置。确保您使用正确的本地项目路径。
5.本地环境设置:
如果您无法在服务器上运行 Composer,请在本地运行它并将供应商文件夹上传到您的服务器。
6.更新特定包:
要更新单个包而不影响其他包,请使用:
To resolve the autoload.php error, follow these steps:
1. Run Composer Install:
composer install
to create thevendor
folder and the autoload script.2. Verify Relative Path:
example, if your scripts are in a subdirectory, use
../vendor/autoload.php.
3. Avoid Composer Update:
dependency issues. Use composer install to avoid breaking changes.
4. Global Composer Installation:
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:
更改 php.ini 上的 auto_prepend_file 属性
Change the auto_prepend_file property on php.ini