2

Hello Good Developers,

I am using spatie:laravel-permissions package in my application. I have identical code in local machine and production server.

I am having a strange issue with my production environment.

I cannot find permission in list of commands in php artisan list.

When I execute php artisan permission:cache-reset it says

There are no commands defined in the "permission" namespace.

I tried following things to fix this issue

  • Spatie\Permission\PermissionServiceProvider::class, in app.php providers

  • composer update

  • composer dump-autoload
  • Cleared all config and application cache.
  • deleted vendors directory and executed composer install to reinstall all the packages.

Still its not working. However when I execute dump-autoload it says Discovered Package: spatie/laravel-permission

I am using Laravel 5.7.28 and spatie/laravel-permission:^2.5

My Local system is working fine and I can see permission command in the list there.

Please help! I don't know where should I check now.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Pankaj Jha
  • 886
  • 15
  • 37
  • Execute `php_sapi_name()` from your CLI on production, what does it return? – Ohgodwhy May 21 '19 at 15:56
  • how do I execute it? should I create a file and put this function there? – Pankaj Jha May 21 '19 at 16:26
  • @Ohgodwhy when I execute this function it says `cgi-fcgi` – Pankaj Jha May 22 '19 at 11:29
  • Then that's the problem. Right there. PHP is not returning `cli` so the `->isRunningInConsole()` check is failing, so the package can't register the commands. – Ohgodwhy May 22 '19 at 15:55
  • Wonderfull! Earlier I was accessing SSH using `root` user and then was switching to domain user to run these commands, now when I am logging directly using domain user I can see `permission` command even I can see `CLI` in `SAPI name` as well. @Ohgodwhy do you know why this magic happened? – Pankaj Jha May 22 '19 at 17:07
  • 1
    I'm not sure to be honest. Many linux environments, many configurations. – Ohgodwhy May 22 '19 at 17:20

1 Answers1

2

Try to run this command:

php artisan optimize:clear

If, for some reason, the command doesn't work, run these one by one:

php artisan view:clear
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan clear-compiled

After one of the above steps, if you are in production environment, run: php artisan config:cache

Thiago Meireles
  • 151
  • 1
  • 5