require(vendor/autoload.php): failed to open stream

匿名 (未验证) 提交于 2019-12-03 02:18:01

问题:

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.

Thanks

回答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.



回答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:

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!



回答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.

  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.



回答6:

run composer update. That's it



回答7:

Change the auto_prepend_file property on php.ini

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


回答8:

Only this: composer require symfony/finder



回答9:

First make sure you have installed the composer.

composer install 

If you already have installed then update the composer.

update composer 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!