问题
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.
回答1:
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 particular reason to. To clarify further - you should probably only ever run composer update
locally, never on your server.
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.
回答2:
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.
回答3:
@Bashir almost helped me but I needed:
composer update --no-scripts
I found the answer here: https://laracasts.com/discuss/channels/general-discussion/fatal-error-class-illuminatefoundationapplication-not-found-in-pathtoprojectbootstrapappphp-on-line-14?page=0
回答4:
First make sure you have installed the composer.
composer install
If you already have installed then update the composer.
composer update
回答5:
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.
- Install composer.exe
- Open CMD Prompt.
+ R + type
CMD
- Run This command:
composer require facebook/graph-sdk
- Include path in your PHP page:
require_once 'C:\Users\<Windows User Name>\vendor\autoload.php';
- Define configuration
Secrets
andAccess Token
for your package...etc. - 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.
回答6:
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.
回答7:
This problem happened with me when I clone projects from git and wanna run for the first time. I ran composer install
in the directory and its work for me.
回答8:
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!
回答9:
run composer update
. That's it
回答10:
I was able to resolve by removing composer and reinstalling the proper way. Here is what I did:
- sudo apt remove composer
- sudo apt autoclean && sudo apt autoremove
- Installed globally with the instructions from: https://getcomposer.org/doc/00-intro.md 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
回答11:
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.
回答12:
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 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.
回答13:
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.
回答14:
Change the auto_prepend_file property on php.ini
; Automatically add files before PHP document.
;http://php.net/auto-prepend-file
auto_prepend_file =
来源:https://stackoverflow.com/questions/41209349/requirevendor-autoload-php-failed-to-open-stream