Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is the use of vendor autoload PHP?

php require "vendor/autoload. php"; This should be right on top of your main application file to make sure, all classes can be found right from the beginning. It loads a PHP file that Composer created automatically ( vendor/autoload.

Where is autoload PHP in laravel?

You can find all the code snippets used in this post in attachments at the end of the post. This code snippet is in folder "php-inbuilt-autoloader-1". You can find all the code snippets used in this post in attachments at the end of the post.

What is autoload in composer JSON?

You just need to provide a list of directories, and Composer will scan all the files in those directories. For each file, Composer will make a list of classes that are contained in that file, and whenever one of those classes is needed, Composer will autoload the corresponding file.

What is autoloading classes in PHP?

The spl_autoload_register() function registers any number of autoloaders, enabling for classes and interfaces to be automatically loaded if they are currently not defined. By registering autoloaders, PHP is given a last chance to load the class or interface before it fails with an error.


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.


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.


@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


First make sure you have installed the composer.

composer install

If you already have installed then update the composer.

composer update

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.


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.


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.