Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EmilMoe's avatar
Level 10

Problem with my package on my server

I have made a package, and it works fine on my Virtual Host Debian, but when I deploy it to my Digital Ocean, also Debian, it gives me an error:

Generating autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize

                                                                  
  [ReflectionException]                                           
  Class vendor\package\App\Console\Commands\Courses does not exist  
                                                                  
Script php artisan optimize handling the post-install-cmd event returned with an error

  [RuntimeException]  
  Error Output:       

I register the commands like this, but as said, they work perfectly on my VM

    public function register()
    {
        $this->mergeConfigFrom(
            __DIR__ .'/config/package.php', 'package'
        );

        $this->commands([
            \vendor\package\App\Console\Commands\Courses::class,
            \vendor\package\App\Console\Commands\Programmes::class,
        ]);
    }

The namespace for Courses is

namespace vendor\package\App\Console\Commands;
0 likes
6 replies
EmilMoe's avatar
Level 10

I tried to clone everything again, but it gives me the same error.

pmall's avatar

If you create a package and want to use it in a project you have to create a repo for this package and add it to your composer.json file. Here you are trying to trick the autoloading mechanism by puttin vendor/package in your namespace, this is to the way these things work.

1 like
SmoDav's avatar

Hey, Have you added the PSR autoloading on your composer.json file pointing to the root of your package namespace?

"Vendor\\"  : "vendor_directory/"
EmilMoe's avatar
Level 10

If you create a package and want to use it in a project you have to create a repo for this package and add it to your composer.json file. Here you are trying to trick the autoloading mechanism by puttin vendor/package in your namespace, this is to the way these things work.

Thanks. Yeah I assume that's about the error. I have tried to move it to a repo, can you point me to where I need to fix the namespace? I feel a bit lost.

EmilMoe's avatar
Level 10

I have this in my autoload

"EmilMoe\\Dashboard\\": "packages/EmilMoe/Dashboard/src/",
"App\\": "app/"

But the dashboard doesn't fail.

The composer.json is the same on the server, so that's why I don't understand why it works on my VM but not on my server

EmilMoe's avatar
EmilMoe
OP
Best Answer
Level 10

I managed to fix them by change this

            App\Console\Commands\Courses::class,
            App\Console\Commands\Programmes::class,

Please or to participate in this conversation.