Artisan 不会在生产中工作,但在本地工作正常

Artisan won't work in production but works fine locally

我正在为生产中的一个问题而烦恼:我无法迁移到 运行。而且,不仅如此, 运行ning 'php artisan' 也会产生错误。奇怪的是,一切都在本地运行良好。

我正在使用 Laravel 5.1 并尝试在服务器上重新克隆我的应用程序,重新安装供应商(刷新作曲家缓存后),重做 .env 并授予适当的权限 bootstrap/cache 和存储文件。我还手动删除了所有 tables,然后,当它不起作用时,删除并重新创建数据库本身。我有 运行 'composer dump-autoload' 很多次,因为我试图找出问题的根源,但没有成功。

我查看了我的日志文件,结果如下:

[2016-06-24 06:07:16] production.ERROR: exception 'ErrorException' with message 'Trying to get property of non-object' in /var/www/html/foobooks/app/Services/PrivacyService.php:157
Stack trace:
#0 /var/www/html/foobooks/app/Services/PrivacyService.php(157): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/var/www/html/l...', 157, Array)
#1 /var/www/html/foobooks/app/Services/DateService.php(69): Foobooks\Services\PrivacyService->getPrivacyLevelIdWithPrivacyLevel('everyone')
#2 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(239): Foobooks\Services\DateService->Foobooks\Services\{closure}()
#3 [internal function]: Illuminate\Cache\Repository->rememberForever('everyone_privac...', Object(Closure))
#4 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(318): call_user_func_array(Array, Array)
#5 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(217): Illuminate\Cache\CacheManager->__call('rememberForever', Array)
#6 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(217): Illuminate\Cache\CacheManager->rememberForever('everyone_privac...', Object(Closure))
#7 /var/www/html/foobooks/app/Services/DateService.php(70): Illuminate\Support\Facades\Facade::__callStatic('rememberForever', Array)
#8 /var/www/html/foobooks/app/Services/DateService.php(70): Illuminate\Support\Facades\Cache::rememberForever('everyone_privac...', Object(Closure))
#9 [internal function]: Foobooks\Services\DateService->__construct(Object(Foobooks\Repositories\Models\DbEventRepository), Object(Foobooks\Services\PrivacyService), Object(Foobooks$
#10 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(780): ReflectionClass->newInstanceArgs(Array)
#11 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Foobooks\...', Array)
#12 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Foobooks\...', Array)
#13 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(220): Illuminate\Foundation\Application->make('Foobooks\...', Array)
#14 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(738): Illuminate\Container\Container->Illuminate\Container\{closure}(Object(Illuminate\Foundation\Application), Array)
#15 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build(Object(Closure), Array)
#16 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Foobooks\...', Array)
#17 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(842): Illuminate\Foundation\Application->make('Foobooks\...')
#18 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#19 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(776): Illuminate\Container\Container->getDependencies(Array, Array)
#20 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Foobooks\...', Array)
#21 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Foobooks\...', Array)
#22 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Console/Application.php(115): Illuminate\Foundation\Application->make('Foobooks\...')
#23 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Console/Application.php(129): Illuminate\Console\Application->resolve('Foobooks\...')
#24 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(226): Illuminate\Console\Application->resolveCommands(Array)
#25 /var/www/html/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Illuminate\Foundation\Console\Kernel->getArtisan()
#26 /var/www/html/foobooks/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}

该应用程序似乎实际上是在尝试在自动加载过程中的某处实例化我的 class DateService(这又实例化了 PrivacyService),这就是导致问题的原因。我已经在我的应用程序中搜索了它被注入的所有实例,但 none 似乎是自动加载过程的一部分 - 而且,它没有解释为什么事情在本地工作得很好。

最初,当 artisan 抱怨时,它给了我一个 'missing base table error' 并且无论出于何种原因,如果我 'fake' 在数据库中创建了 table 然后手动删除它,应用程序继续抱怨另一个 table,直到我再次完成手册 create/drop。我能够以这种方式解决 table 错误,直到遇到此 'Trying to get property of non-object' 错误。

有谁知道可能是什么问题?感觉好像有某种我不知道的数据库缓存文件挂在某处并导致此问题,使应用程序认为 migrations/seeds 已经发生。在出现此错误之前,创建假 tables 并删除它们似乎在做某事似乎很奇怪 - 而且,奇怪的是只有生产环境受到影响。

任何帮助或见解将不胜感激 - 谢谢!

解决方案:由于某些原因,我的缓存文件夹中的某些文件夹的权限与其他文件夹不同,因此 flush() 方法没有完全清除缓存。遗留 folders/files 与 artisan 的引导工作相冲突。我能够通过重新应用对 storage/framework/cache 目录的权限来解决问题,再次 运行ning flush() 。一旦我这样做并确保所有子文件夹和文件都从缓存中删除,我就能够 运行 php artisan 顺利进行。