I have a web application in a production environment. The path to the command is correctly set on the server, but it still throws error “IlluminateConsoleCommand” not found. Solutions tryied -> (composer dump-autoload, deleted vendor and reinstalled with composer install, php artisan optimize). Nothing works :/
Fatal error: Uncaught Error: Class “IlluminateConsoleCommand” 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 AppConsoleCommands;
use CarbonCarbon;
use IlluminateConsoleCommand;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesLog;
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');
}
}
This is my kernel.php
<?php
namespace AppConsole;
use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel 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');
}
And this is composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"require": {
"php": "^8.1",
"erlandmuchasaj/laravel-gzip": "^1.0",
"guzzlehttp/guzzle": "^7.2",
"jantinnerezo/livewire-alert": "^3.0",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8",
"livewire/livewire": "^3.4",
"propaganistas/laravel-phone": "^5.0"
},
"require-dev": {
"fakerphp/faker": "^1.23",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi",
"@php artisan vendor:publish --force --tag=livewire:assets --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r "file_exists('.env') || copy('.env.example', '.env');""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
I’ll be glad if anybody has idea how can I solve that issue 🙂 Thank you
So I crated this custom script in www folder
#!/usr/bin/env php
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$commandName = 'app:delete-expired-data';
$kernel = $app->make(IlluminateContractsConsoleKernel::class);
$input = new SymfonyComponentConsoleInputArgvInput(['artisan', 'schedule:run']);
$status = $kernel->handle($input, new SymfonyComponentConsoleOutputConsoleOutput);
$kernel->terminate($input, $status);
exit($status);
In server cron log I have got this, is there any possible solution how to solve that? Because I can’t edit proc_open on server.. 🙁
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
But in storage/logs it shows this error
production.ERROR: The Process class relies on proc_open, which is not available on your PHP installation. {"exception":"[object] (SymfonyComponentProcessExceptionLogicException(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): SymfonyComponentProcessProcess->__construct(Array, '/srv/www/myDomain...', NULL, NULL, NULL)
19
Okey,, finally a I did solve that with this option, and it works! 🙂
#!/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(IlluminateContractsContainerContainer::class);
$kernel = $container->make(IlluminateContractsConsoleKernel::class);
$commandName = 'delete-expired-data';
$input = new SymfonyComponentConsoleInputArgvInput(['console.php', $commandName]);
$status = $kernel->handle($input, new SymfonyComponentConsoleOutputConsoleOutput);
$kernel->terminate($input, $status);
exit($status);
4