require(vendor/autoload.php): Failed to open stream: No such file or directory
Warning: require(vendor/autoload.php): Failed to open stream: No such file or directoryShort answer
PHP looked for vendor/autoload.php at a path where it does not exist. Either Composer never ran in this folder, so vendor is missing, or the require uses a path relative to the wrong directory. Run composer install next to composer.json and require the file with __DIR__.
Fix it fast
1Find out which cause you have
Check whether the file exists at all, from the folder that holds composer.json.
ls -l vendor/autoload.php ls composer.json2Match what you see, then jump to its fix
- 1
ls: cannot access 'vendor/autoload.php': No such file or directoryComposer was never run here, so there is no vendor folderFix - 2
vendor/autoload.php exists, yet the error still names the short relative pathThe path is relative to the wrong directoryFix - 3
autoload.php exists, but a class from your own namespace is not found afterwardscomposer.json changed and the autoloader is staleFix
- 1
What does the error look like?
Warning: require(vendor/autoload.php): Failed to open stream: No such file or directoryFatal error: Uncaught Error: Failed opening required 'vendor/autoload.php'
Cause 1 of 3
Composer was never run here, so there is no vendor folder
1Check
vendor/ is normally excluded from Git. A fresh clone, a ZIP upload or a deploy without a Composer step has composer.json but no vendor folder.
ls composer.json composer.lock
cat .gitignore | grep vendor2Fix
Run Composer in the folder that contains composer.json. composer install reads composer.lock and creates vendor/ including autoload.php.
composer install3Verify
The file now exists.
ls -l vendor/autoload.phpConfirmed by getcomposer.org
Cause 2 of 3
The path is relative to the wrong directory
1Check
A relative path is resolved against the current working directory or include_path, not against the file that contains the require. A script in a sub-folder, or a cron job started from elsewhere, looks in the wrong place.
find . -name autoload.php -path "*vendor*" -maxdepth 3
pwd2Fix
Build the path from the location of the current file with __DIR__. Count the folders between this file and the folder that holds vendor/.
<?php
// file is in the project root
require __DIR__ . '/vendor/autoload.php';
// file is in public/ and vendor is one level up
require __DIR__ . '/../vendor/autoload.php';3Verify
Run the script from a different folder and it still loads.
cd / && php /var/www/app/send-mail.phpConfirmed by getcomposer.org
Cause 3 of 3
composer.json changed and the autoloader is stale
1Check
After you add or change the autoload field in composer.json, the generated autoloader has to be rebuilt.
grep -n -A4 '"autoload"' composer.json2Fix
Regenerate the autoloader.
composer dump-autoload3Verify
The class now loads.
php -r 'require "vendor/autoload.php"; var_dump(class_exists("App\\Mailer"));'Confirmed by getcomposer.org
How do I stop it coming back?
- Add composer install --no-dev to the deploy script, run in the release folder.
- Always require with __DIR__, never a bare relative path.
- Commit composer.lock so every machine installs the same versions.
- Do not commit vendor/; rebuild it on each deploy.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix