I Upload a laravel project into plesk and I have problems with laravel/sanctum

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Fixing Laravel Sanctum Errors After Deployment: A Deep Dive into Composer and Framework Integrity

Deploying a Laravel application, especially one involving authentication features like Sanctum, onto a new server environment like Plesk can often introduce unexpected hurdles. The error you are facing—Class 'Laravel\Sanctum\Sanctum' not found combined with complex Composer dependency conflicts—is a classic symptom of corrupted dependencies or mismatched framework versions on the hosting environment.

As a senior developer, I can tell you that this issue is rarely about Sanctum itself; it’s usually about the underlying integrity of your vendor directory and how Laravel manages its class loading (PSR-4). Let's break down why this happens and how to fix it systematically.

Understanding the Root Cause: Broken Autoloading

The error message, specifically the failure to find Laravel\Sanctum\Sanctum, points directly to a problem in how PHP is locating the necessary classes. When Composer fails during an update (as seen in your output regarding dependency resolution and PSR-4 skipping), it means the file structure or the installed packages are inconsistent.

The cascade of errors you observed—warnings about deprecated Carbon usage, abandoned packages, and numerous "Class ... does not comply with psr-4 autoloading standard" notices—all confirm that the core framework files have been partially corrupted or mismatched during the deployment process on your Plesk server. The application code expects a certain structure from Laravel, but the installed dependencies do not provide it correctly.

Step-by-Step Troubleshooting Guide

To resolve this, we need to enforce a clean state and ensure all dependencies are correctly aligned with your Laravel version. Follow these steps precisely:

1. Clean Up Composer Dependencies

Start by clearing any potentially corrupted cache files and attempting a full dependency resolution again. This is the most crucial step for fixing autoloading issues.

Run the following commands from your project root on the server:

# Clear the composer cache
composer clear-cache

# Remove existing vendor files and lock file (use with caution, ensure you have backups)
rm -rf vendor/
rm composer.lock

# Reinstall all dependencies based on composer.json
composer install --no-dev --optimize-autoloader

The --no-dev flag ensures we only install production dependencies, which cleans up the noise from abandoned packages seen in your log. The --optimize-autoloader flag forces Composer to regenerate optimized class maps, which should resolve the PSR-4 autoloading warnings you encountered.

2. Address Framework and Version Conflicts

Since you are deploying a pre-existing project, sometimes forcing an update on related packages helps harmonize the environment. If the above step fails, try updating the core framework components directly:

# Attempt to update Laravel components if necessary
composer update laravel/framework

If this command still throws errors, it signals a deeper incompatibility between your installed PHP version (the one running on Plesk) and the dependencies specified in the project's composer.json. In such cases, you might need to adjust the required Laravel version or ensure your PHP environment meets the requirements of the specific application you are deploying.

3. Verify Sanctum Installation

Once the dependency resolution is successful, try installing Sanctum again:

composer require laravel/sanctum

This time, because the base framework and dependencies are clean, the installation should proceed without conflicting with existing structures, allowing Sanctum to be correctly registered within the Laravel structure.

Best Practices for Deployment on Shared Hosting

When deploying Laravel applications, especially those involving external packages like Sanctum, remember that environment consistency is key. Always ensure your server's PHP version and extensions match what the application was built for. Furthermore, always follow the official documentation provided