Fatal error: Class "Firebase\JWT\JWT" not found
Fatal error: Uncaught Error: Class "Firebase\JWT\JWT" not foundShort answer
PHP cannot find the class because the package is not installed, the Composer autoloader is never loaded, or the file lacks a use statement. Run composer show firebase/php-jwt, require vendor/autoload.php once at the entry point, and import Firebase\JWT\JWT and Firebase\JWT\Key at the top of the file.
Fix it fast
1Find out which cause you have
Ask Composer whether the package is installed in this project, then check the vendor folder on the server that shows the error.
composer show firebase/php-jwt ls vendor/firebase/php-jwt/src2Match what you see, then jump to its fix
- 1
composer show says the package is not found, or vendor/ is missing on the serverThe package is not installed on this machineFix - 2
The package is installed, yet every class from vendor/ is missingvendor/autoload.php is never loadedFix - 3
The message names a different class such as App\Controllers\JWT, or the code says new JWT or \JWTThe file has no use statement, or the namespace is wrongFix
- 1
What does the error look like?
Fatal error: Uncaught Error: Class "Firebase\JWT\JWT" not foundClass 'Firebase\JWT\JWT' not found
Cause 1 of 3
The package is not installed on this machine
1Check
A deploy that skips vendor/ (it is usually in .gitignore) leaves the server without the library.
composer show firebase/php-jwt2Fix
Add the package, and on the server run install so it matches composer.lock.
composer require firebase/php-jwt
# on the server, after deploying composer.json and composer.lock
composer install3Verify
composer show now lists the package and the folder exists.
ls vendor/firebase/php-jwt/src/JWT.phpConfirmed by github.com
Cause 2 of 3
vendor/autoload.php is never loaded
1Check
Composer generates vendor/autoload.php for libraries that provide autoload information, and the entry script must include it. Look for the require in your front controller.
grep -rn "vendor/autoload.php" index.php public/ src/ 2>/dev/null2Fix
Require the autoloader once, before the first use of any package class, with a path relative to the file.
<?php
require __DIR__ . '/vendor/autoload.php';3Verify
Reload the page; the error should change or disappear.
php -r 'require "vendor/autoload.php"; var_dump(class_exists("Firebase\\JWT\\JWT"));'Confirmed by getcomposer.org
Cause 3 of 3
The file has no use statement, or the namespace is wrong
1Check
Inside a namespaced file an unqualified class name is looked up in the current namespace, and PHP does not fall back to the global one. Imports are per file, so each file needs its own.
grep -n "^use \|^namespace " src/AuthController.php2Fix
Import both classes the library uses for decoding, and pass a Key object with the algorithm.
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
$decoded = JWT::decode($token, new Key($secret, 'HS256'));3Verify
Run the code path with a valid token; it returns the payload object.
php -l src/AuthController.phpConfirmed by php.net
How do I stop it coming back?
- Commit composer.json and composer.lock, and run composer install in every deploy.
- Keep one require of vendor/autoload.php in the entry point, not in each file.
- Let your editor add use statements when you type a class name.
- Pin the package version in composer.json so decode() usage stays stable.
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:
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Back end
require(vendor/autoload.php): Failed to open stream: No such file or directory
Fatal error: Uncaught Error: Failed opening required 'vendor/autoload.php'
PHP looked for vendor/autoload.php at a path where it does not exist.
3 causes, each with a fixBack end
PHP says Class not found, but the file is there
Class not found, although the file is included
PHP finds a class only if the file defining it was already loaded or an autoloader can map the name to a file.
3 causes, each with a fixBack end
JWT::decode() says the kid is empty and cannot find the key
UnexpectedValueException
This message means you gave JWT::decode() an array of keys, but the token header has no kid to pick one with.
3 causes, each with a fixBack 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 fix