Skip to content
PHP and Laravel3 min read

PHP "Class not found": causes and fixes

PHP Fatal error: Uncaught Error: Class "App\Services\PaymentService" not found

Short answer

"Class not found" means PHP couldn't find the class definition when the code used it. In Composer projects it's usually a missing vendor folder or stale autoload files, a namespace that doesn't match the file path, or the wrong filename case on a Linux server. Run composer install, then composer dump-autoload, and check the path.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What the error means
  2. Common causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

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 vendor folder: it’s normally excluded from Git, so deploying from GitHub without running composer install leaves no libraries and no vendor/autoload.php.
  • Stale autoload files after adding a class or moving a file, especially with --optimize-autoloader.
  • Filename case: app/services/paymentservice.php works on your laptop and fails on Linux.
  • Namespace doesn’t match the folder, or a missing use line, 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) or SoapClient (soap).
  • Laravel cache files in bootstrap/cache uploaded from your machine and pointing to dev packages that aren’t on the server.

How to fix it

  1. Install packages if vendor is missing, from the project folder over SSH:
composer install --no-dev --optimize-autoloader
  1. Regenerate the autoloader after adding or moving classes:
composer dump-autoload -o
  1. 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
  1. Enable the extension if it’s a PHP class: in cPanel open Software › Select PHP Version and tick the extension under Extensions.
  2. Clear Laravel’s caches: delete bootstrap/cache/packages.php and bootstrap/cache/services.php, then run:
php artisan optimize:clear
php artisan package:discover
  1. Without SSH: run composer install --no-dev --optimize-autoloader on your computer, zip the vendor folder, upload it in Files › File Manager and Extract it inside the project folder.

Prevention

  • Make composer install a fixed step in every deploy, as in the Laravel deployment guide.
  • Never upload bootstrap/cache/*.php from 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.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.