Common causes
- vendor/autoload.php is not required, or the vendor folder was not uploaded or installed
- The namespace declaration or file path does not match the PSR-4 mapping in composer.json
- Filename case differs from the class name, which works on Windows/macOS but fails on Linux
- The autoload cache is stale after adding or moving classes
- A missing use statement, so PHP looks for the class in the current namespace
- A PHP extension that provides the class (pdo_mysql, redis, intl, zip) is not installed
How to fix it
- Regenerate the autoloader. Run composer dump-autoload (or composer dump-autoload -o in production). If vendor is missing entirely, run composer install --no-dev.
- Check namespace, path and case. With "App\\": "app/" in composer.json, the class App\Http\Controllers\UserController must live in app/Http/Controllers/UserController.php with exactly that capitalization and declare namespace App\Http\Controllers;.
- Add the use statement. Inside a namespaced file, add use App\Models\User; at the top, or reference the class with a leading backslash such as \DateTime. Without it PHP looks in the current namespace.
- Install the package. If the class comes from a library, run composer require vendor/package and commit both composer.json and composer.lock so other environments install it too.
- Install the extension for built-in classes. For PDO, Redis, IntlDateFormatter or ZipArchive, install the extension (for example sudo apt install php8.3-mysql php8.3-redis) and restart PHP-FPM. Confirm with php -m.
- Clear framework caches. In Laravel run php artisan optimize:clear; in Symfony run php bin/console cache:clear. Cached route or container files can still reference renamed classes.
composer.json PSR-4 mapping
{
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
// app/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;
class UserController {}
// then run: composer dump-autoload How to stop it happening again
- Run composer install as part of every deployment instead of copying vendor by hand
- Develop on a case-sensitive filesystem or run CI on Linux
- Declare required extensions such as ext-pdo or ext-redis in composer.json
- Rename classes with an IDE refactor so the filename and namespace stay in sync