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

本文解决了PHP项目中Composer导致的找不到vendor/autoload.php文件的问题。通过正确安装和更新Composer、调整autoload路径等方法,帮助开发者顺利运行项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

21down votefavorite

6

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

composer-php phpmailer

shareimprove this question

edited Dec 18 '16 at 15:01

asked Dec 18 '16 at 14:33

adrTuIPKJ44

138117

  • This can also occur if you have php artisan up or down in your composer.json file in the scripts section on pre-install. It seems to need files in the vendor folder to execute the maintenance mode, which isn't available as yet. – Thomas Mar 2 at 10:18

add a comment

11 Answers

activeoldestvotes

up vote43down voteaccepted

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.

shareimprove this answer

edited Dec 18 '16 at 19:43

answered Dec 18 '16 at 15:01

Synchro

16.2k85071

show 3 more comments

 

up vote8down vote

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.

shareimprove this answer

answered Nov 27 '17 at 17:17

mbouzahir

659714

add a comment

up vote5down vote

@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

shareimprove this answer

answered Jan 28 at 14:26

mcmacerson

325139

add a comment

up vote3down vote

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.

shareimprove this answer

answered Nov 2 '17 at 20:32

wpcoder

448310

add a comment

up vote2down vote

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!

shareimprove this answer

edited Aug 22 '17 at 14:21

answered Jun 13 '17 at 18:05

jjoselon

503214

add a comment

up vote0down vote

First make sure you have installed the composer.

composer install

If you already have installed then update the composer.

update composer

shareimprove this answer

edited Apr 28 at 8:31

Community

11

answered Apr 26 at 14:25

IsharaNW

111

  • This answer needs serious editing to be helpful to a user. Please clearly state your suggestions and provide code samples that would be useful in this situation. – Stefan Crain Apr 26 at 14:48

add a comment

up vote0down vote

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

shareimprove this answer

answered May 18 at 18:44

nwolybug

320212

add a comment

up vote-1down vote

run composer update. That's it

shareimprove this answer

answered Dec 20 '17 at 9:38

Bashir ahmad

6010

add a comment

up vote-1down vote

Change the auto_prepend_file property on php.ini

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

shareimprove this answer

answered Feb 19 at 7:37

ercvs

389

  • How does this relate to the question? There is an accepted answer with a completely other solution – Nico Haase Feb 19 at 8:03

  • I had the following error in this morning. "Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0" Therefore I writed this solution. – ercvs Feb 19 at 8:48

add a comment

up vote-1down vote

Only this: composer require symfony/finder

shareimprove this answer

answered Apr 12 at 11:50

Ramus B

1

add a comment

up vote-1down vote

***PHP Warning: require_once(C:\xampp\htdocs\test1/bootstrap/app.php): failed to open stream: No such file or directory in C:\xampp\htdocs\test1\artisan on line 20 Warning: require_once(C:\xampp\htdocs\test1/bootstrap/app.php): failed to open stream: No such file or directory in C:\xampp\htdocs\test1\artisan on line 20 PHP Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\test1/bootstrap/app.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\test1\artisan on line 20

Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\test1/bootstrap/app.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\test1\artisan on line 20***

This problem due to the missing of bootstrap file in your project folder..This problem can not fix by using reinstalling or updating composer.. you can fix by using : if you have another project available just open that project and copy bootstrap file folder and past to your missing project folder for example: i have two project test 1 and test 2 (you can create your project by using cmd => Composer create-project laravel/laravel test 1 ) now go to atom and open project test 1 and test 2 . this error occurs in test 1,you can just copy bootstrap file from test 2 and past to test 1.save changes.. then go to cmd just type php artisan serve .. then your problem is solved.

shareimprove this answer

edited Jul 1 at 2:58

answered Jul 1 at 2:18

Ajmal C

12

add a comment

Your Answer

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

 

Sign up or log in

 Sign up using Google

 Sign up using Facebook

 Sign up using Email and Password

 

Post as a guest

Name

Email

Post Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of serviceprivacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged composer-php phpmailer or ask your own question.

asked

1 year, 7 months ago

viewed

89,647 times

active

1 month ago

 

Want a php job?

Linked

0

WARNING : require(vendor/autoload.php)

0

Vendor autoload directory error

Related

1

Require_once(Net/URL2.php): failed to open stream: no such file or directory

1

composer autoload.php failed to open stream: no such file or directory

1

Failed opening required '../vendor/autoload.php'

1

Fresh Composer install is giving errors on a new git project cloned

0

phpmailer - vendor/autoload.php issues xampp windows

2

Laravel 5.2 - Error while installing laravel using composer with git bash

-6

Warning message in laravel

0

How to create custom helper file in laravel 5.6?

0

No vendor/autoload.php file in Laravel folder after installation

0

'vendor/autoload.php' errors, composer is installed globally

Hot Network Questions

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值