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

jakubjv's avatar

How solve "Illuminate\Console\Command" not found ??

Hello, I've got webapp in production enviroment, path to comman is set correctly on serveer, but it still throwing this error ->

Fatal error: Uncaught Error: Class "Illuminate\Console\Command" not found in app/Console/Commands/DeleteExpiredData.php:10
Stack trace:
#0 {main}
  thrown in /app/Console/Commands/DeleteExpiredData.php on line 10

Illuminatie is available in vendor and correctly installed, I did try composer dump-autoload but it still doesn't work.

This is my command

<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class DeleteExpiredData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'delete-expired-data';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Delete old data from database';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $now = Carbon::now();
        Log::info('Starting app:delete-expired-data command');

        DB::table('available_business_hour')
            ->whereDate('day', '<', $now->startOfDay())
            ->delete();

        Log::info('Expired command executed successfully');
    }

}

I'll be glad if anybody has idea how can I solve that issue :) Thank you

0 likes
32 replies
Kortez12's avatar

Try to delete vendor folder and run composer install and check then if it's working or not

jakubjv's avatar

@Kortez12 okay I deleted vendor and reinstall with composer install, and it still throw the same error

gych's avatar

Try to run composer dump auto-load via terminal

gych's avatar

@jakubjv Are you running this command via the terminal or from the code? If from code, does it work via terminal?

jakubjv's avatar

@gych command is setup for cron, which is running on shared hosting, if i run comman via ssh terminal on hosting as "php artisan delete-expired-data" .. it works, but just in case if I run it manually through command in ssh terminal. But it doesn't work as a scheduled cron on shared hosting and it's throwing error which I described in my question .. :/

Snapey's avatar

@jakubjv show your scheduler, and next time mention that in your question

2 likes
jakubjv's avatar

@Snapey Ok I'm sorry about that. So this is scheduler

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('delete-expired-data')->daily();
        // $schedule->command('delete-unconfirmed-res')->everyFiveMinutes();
    }

    /**
     * Register the commands for the application.
     */
    protected function commands(): void
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }


}

On the server, I don't have access to cron tab, all what I can do is just setup cron in admin GUI, where I made setup like this

Path to command:
/barbershop27/app/Console/Commands/DeleteExpiredData.php

Time setup: 
	
Minute: 00
Hour: 12AM
Day: each day
Week: each week
Month: each month
jakubjv's avatar

@puklipo I can't proceed that command on my shared hosting SERVER. I'm not alloved to do that, everything what's needs to be done is that, i have to specify path to my command on server GUI administration tab, which i descriped in answer to snapey above. This is description of procedure for adding a cron job on my shared hosting -->

File name - PHP Script. Enter relative path (case sensitive) from root directory of your domain. Enter the path from the same level where direcory www is. Eg. /www/cron/file.php
Snapey's avatar

@jakubjv your cron should be for the schedule not the command class. There is no way you can run a class without the framework.

Path to command:
/barbershop27/artisan schedule:run
gych's avatar

@jakubjv You should run the sheduler via your cron job and not the command itself

Create a php file in www: runSheduler.php I've never used this approach but you could try something like this:

<?php

chdir('barbershop27');
exec('php artisan schedule:run');
jakubjv's avatar

@gych I did try that and these methods are not allowed on server for me unfortunately according to log after I setup cron..

jakubjv's avatar

@Snapey This returns me ->

Enter a valid file name within the domain's scope.
jakubjv's avatar

@Snapey This is structure what i have

/
├── www
│   ├── index.php
│   ├── assets
│   │   ├── css
│   │   └── js
│   ├── css
│   └── js
└── barbershop27
    ├── .env
    ├── app
    │   └── ...
    ├── bootstrap
    │   └── ...
    ├── config
    │   └── ...
    ├── database
    │   └── ...
    ├── public -> www
    ├── resources
    │   └── ...
    ├── routes
    │   └── ...
    ├── storage
    │   └── ...
    ├── tests
    │   └── ...
    └── vendor
        └── ...

just don't be confused, public folder is not anymore in barbershop27 folder, it's content is available in www folder.

In app\Console\Commands I have command DeleteExpiredData.php which i need to somehow setup for scheduled cron,, But everything what i can do in server administration is that I can add path to script according to this line of text->

File name - PHP Script. Enter relative path (case sensitive) from root directory of your domain. Enter the path from the same level where direcory www is. Eg. /www/cron/file.php

And while I set path like this

/barbershop27/app/Console/Commands/DeleteExpiredData.php

Support of shared hosting is telling me that the path is correct but I'm getting error, which I described in the question.

Fatal error: Uncaught Error: Class "Illuminate\Console\Command" not found in app/Console/Commands/DeleteExpiredData.php:10
Stack trace:
#0 {main}
  thrown in /app/Console/Commands/DeleteExpiredData.php on line 10
Snapey's avatar

@jakubjv The path I gave earlier seems fine. If they are rejecting it just because the file does not contain the php extension then you can rename artisan file to add .php then use the command

Path to command:

/barbershop27/artisan.php schedule:run
jakubjv's avatar

@Snapey I did try it and it stills throws me error ,, The problem is they are rejicting specifically this part "schedule:run" they have problem with colon i think and they don't accept that..

Enter a valid file name within the domain space.
Snapey's avatar

@jakubjv I suggest you ask them, you cant be their only ever Laravel customer?

jakubjv's avatar

@Snapey This is answer from hosting support -> Hello, you set up cron to point to a .php file without any parameters. Cron will then execute the specified file at the configured intervals.

If I have this file located, for example, in the www/cron directory, then the cron setting will be: www/cron/myscript.php

If I have this file located, for example, in the cron directory at the same level as www, then the cron setting path will be: /cron/myscript.php

Pay attention to uppercase/lowercase letters. Therefore, enter only the file path without any parameters.

jakubjv's avatar

@Snapey they told me that someone is solving this problem with this -> #!/usr/bin/env php

Snapey's avatar
Snapey
Best Answer
Level 122

@jakubjv Then you would need to come up with a php script that runs artisan or emulates it.

The following can be saved as scheduler.php

#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
    $input = new Symfony\Component\Console\Input\ArgvInput(['artisan','schedule:run']),
    new Symfony\Component\Console\Output\ConsoleOutput
);

/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/

$kernel->terminate($input, $status);

exit($status);

Then run it with the cron.

You can test it with php scheduler.php and you will find its the same as artisan schedule:run

It must live in the laravel folder and not www/cron

Note that this is a copy of artisan with one line changed

new Symfony\Component\Console\Input\ArgvInput(['artisan','schedule:run']),

which passes the command the schedule:run string meaning its not needed in the cron setting

1 like
jakubjv's avatar

@Snapey Thanks for help, so this is now output in server cron log

Tue 05 Mar 2024 04:35:23 PM CET Executing /srv/www/myDomain//barbershop27/scheduler.php

  2024-03-05 16:35:23 Running ['artisan' delete-expired-data] ....... 8ms DONE
  ⇂ '/usr/bin/php8.2' 'artisan' delete-expired-data > '/dev/null' 2>&1  

so now finally it looks like it can work, but unfortunately it doesnt delete data which should be deleted, it still deletes data just if i put php delete-expired-data into shell so i know that command works if we are talking about logic,, but cron isnt still able to delete data automatically..

and this is in my storage logs in laravel app

[2024-03-05 16:35:23] production.ERROR: The Process class relies on proc_open, which is not available on your PHP installation. {"exception":"[object] (Symfony\Component\Process\Exception\LogicException(code: 0): The Process class relies on proc_open, which is not available on your PHP installation. at /srv/www/myDomain/barbershop27/vendor/symfony/process/Process.php:147)
[stacktrace]
#0 /srv/www/myDomain/barbershop27/vendor/symfony/process/Process.php(192): Symfony\Component\Process\Process->__construct(Array, '/srv/www/myDomain...', NULL, NULL, NULL)

Snapey's avatar

@jakubjv and you don't see either of your log messages?

I'm afraid that this is a question again for your not very impressive hosts. They seem to run cron under a restricted user account. You need to ask why proc_open is not available

jakubjv's avatar

@Snapey I send them question bout it, but I think this is probably last time when I bought hosting from them. It's same problem like with exec() function, this throws me same error with proc_open aswell, so this is for 100% problem with permissions. First time their permissions on server literally blocked my livewire script, I argued with them for one week to solve it.. Will let you know after I will solve this permission error with them. But I think after that this solution will works :)

andreigirnet96's avatar

Navigate to root folder, remove vendor and run composer install again. Usually this will solve the dependencies issues related to Laravel

jakubjv's avatar

@Snapey 1 hour ago I send them next question on support where I described every solution which I tryied, so i hope they will respond this day... But they have very specific setup, I did always setup cron through command line or with command in the path like u adviced me :/ So we'll see.

Snapey's avatar

An alternative is to forget their cron, and write your job into a web request;

web.php

route::get('gobbledygook', function(){

        DB::table('available_business_hour')
            ->whereDate('day', '<', today())
            ->delete();
});

and then setup a free account at https://cron-job.org/en/ and ask it to hit your gobbledygook endpoint at your desired interval.

change 'gobbledygook' to whatever meaningless string you like.

1 like
jakubjv's avatar

@Snapey if they will not be helpfull I will try it like this :) thanks for next advice!

jakubjv's avatar

@Snapey

Okey,, finally a I did solve that with this option, and it works! :) But it was pain AF.. Thanks a a lot for your help man!

#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';

$container = $app->make(Illuminate\Contracts\Container\Container::class);

$kernel = $container->make(Illuminate\Contracts\Console\Kernel::class);

$commandName = 'delete-expired-data';

$input = new Symfony\Component\Console\Input\ArgvInput(['console.php', $commandName]);

$status = $kernel->handle($input, new Symfony\Component\Console\Output\ConsoleOutput);

$kernel->terminate($input, $status);

exit($status);

Please or to participate in this conversation.