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

Prabakaran's avatar

Can't use shell_exec for laravel artisan command in live server

I am using shell_exec command to run my artisan commands in the background. But when I run shell_exec in production server.

The route code as follows

Route::get('/test/exec', function () {
    echo shell_exec('php ../artisan migrate:status 2>&1; echo $?');
});

it throws me error as follows.

PHP Fatal error: Cannot redeclare class Illuminate\Support\Traits\Macroable in /var/www/production/bootstrap/cache/compiled.php on line 6109 255

But when I run the same command in my local I got the output.

  • Laravel versin - 5.1.46
  • php version - PHP 5.5.9
  • os version - ubuntu 14.04

These are same on both servers. Where things went wrong. Please, some one helps me with this.

0 likes
0 replies

Please or to participate in this conversation.