Modern PHP doesn’t load classes with manual require calls; an autoloader does it, most often the one Composer generates. So this error is usually about how files get loaded rather than the code itself. Start with the full class name in the message, namespace included.
What the error means
PHP Fatal error: Uncaught Error: Class "App\Services\PaymentService" not found in /home/user/myapp/app/Http/Controllers/CheckoutController.php:24
Line 24 tried to use App\Services\PaymentService, so PHP asked the autoloader for it. Composer maps the name to a path under PSR-4 rules, here app/Services/PaymentService.php. If the file isn’t there, or the class isn’t inside it, you get this error.
Common causes
- No
vendorfolder: it’s normally excluded from Git, so deploying from GitHub without runningcomposer installleaves no libraries and novendor/autoload.php. - Stale autoload files after adding a class or moving a file, especially with
--optimize-autoloader. - Filename case:
app/services/paymentservice.phpworks on your laptop and fails on Linux. - Namespace doesn’t match the folder, or a missing
useline, so PHP looks in the current file’s namespace. - A package installed as require-dev, then installed on the server with
--no-dev. - A class from a disabled PHP extension, such as
ZipArchive(zip),Redis(redis),Imagick(imagick),NumberFormatter(intl) orSoapClient(soap). - Laravel cache files in
bootstrap/cacheuploaded from your machine and pointing to dev packages that aren’t on the server.
How to fix it
- Install packages if
vendoris missing, from the project folder over SSH:
composer install --no-dev --optimize-autoloader
- Regenerate the autoloader after adding or moving classes:
composer dump-autoload -o
- Match path and name to the PSR-4 setting in
composer.json:
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
App\Services\PaymentService must live in app/Services/PaymentService.php with exactly the same case, and the file must start with namespace App\Services;.
4. Add the use line in the file that uses the class:
namespace App\Http\Controllers;
use App\Services\PaymentService; // without it PHP looks for App\Http\Controllers\PaymentService
- Enable the extension if it’s a PHP class: in cPanel open Software › Select PHP Version and tick the extension under Extensions.
- Clear Laravel’s caches: delete
bootstrap/cache/packages.phpandbootstrap/cache/services.php, then run:
php artisan optimize:clear
php artisan package:discover
- Without SSH: run
composer install --no-dev --optimize-autoloaderon your computer, zip thevendorfolder, upload it in Files › File Manager and Extract it inside the project folder.
Prevention
- Make
composer installa fixed step in every deploy, as in the Laravel deployment guide. - Never upload
bootstrap/cache/*.phpfrom your machine to the server. - Name files with the same case as the class from day one.
- Declare required extensions in
composer.json, such as"ext-zip": "*".
On ArabyHost
AI/Developer plans include SSH jailed in CageFS with Composer and Git, so you run composer install and composer dump-autoload on the server directly. Shared and WordPress plans have no SSH: build vendor on your computer and upload it as a ZIP, or deploy through Git as in the cPanel Git deployment guide. PHP 8.1 to 8.3 extensions are enabled per site in Select PHP Version, and the Araby AI assistant reads the error log and names the missing class and file.
FAQ
Why does it work on my machine but fail on the server?
Usually filename case. Windows and macOS don't distinguish orderitem.php from OrderItem.php by default, but Linux servers do. The file name must match the class name exactly.
Should I upload the vendor folder?
If you have SSH and Composer on the server, run composer install there. If not, run composer install --no-dev on your computer and upload the vendor folder with the project.
How is this different from Laravel's "Target class does not exist"?
"Class not found" comes from PHP itself when the class is used. "Target class does not exist" comes from Laravel's container when it can't build a class named in a route or binding. Both usually come down to namespaces or autoloading.