部署Laravel应用程序会中断应用程序,直到手动运行composer install

前端之家收集整理的这篇文章主要介绍了部署Laravel应用程序会中断应用程序,直到手动运行composer install前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用Passport的Laravel应用程序来提供API身份验证.该应用程序使用带有post-receive挂钩的git进行部署.接收后脚本的一部分是作曲家安装.自从我包含Passport以来,每当我部署我的应用程序时,API都会在身份验证门后面的路由上中断,并在下面粘贴堆栈跟踪.

当我进入应用程序的服务器并运行与我的post-receive挂钩完全相同的composer install命令时,事情再次正常工作.

当部署发生时,我没有看到来自git的任何错误消息,并且当部署发生时和我手动运行命令时,我看起来从composer install获得相同的输出.

这是composer install命令的deploy输出

remote: Loading composer repositories with package information        
remote: Installing dependencies (including require-dev) from lock file        
remote: Nothing to install or update        
remote: Generating autoload files        
remote: > PHP artisan clear-compiled        
remote: The compiled class file has been removed.        
remote: > PHP artisan optimize        
remote: Generating optimized class loader        
remote: Compiling common classes

这是我手动运行命令时看到的内容

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> PHP artisan clear-compiled
The compiled class file has been removed.
> PHP artisan optimize
Generating optimized class loader
Compiling common classes

这里发生了什么?似乎部署正在安装Passport的某个组件的旧版本,然后在手动运行composer安装后进行更正,但我不知道为什么会发生这种情况,特别是为什么每次部署时都会发生这种情况.即使对composer.json或composer.lock没有任何更改,也会进行新的更新.

这是上面提到的堆栈跟踪:

[2017-01-04 20:36:37] production.ERROR: exception 'BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder::withAccessToken()' in /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.PHP:2450
Stack trace:
#0 [internal function]: Illuminate\Database\Query\Builder->__call('withAccessToken',Array)
#1 [internal function]: Illuminate\Database\Query\Builder->withAccessToken(Object(Laravel\Passport\Token))
#2 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.PHP(1469): call_user_func_array(Array,Array)
#3 [internal function]: Illuminate\Database\Eloquent\Builder->__call('withAccessToken',Array)
#4 [internal function]: Illuminate\Database\Eloquent\Builder->withAccessToken(Object(Laravel\Passport\Token))
#5 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(11801): call_user_func_array(Array,Array)
#6 /home/portalvarius/app/production/vendor/laravel/passport/src/Guards/TokenGuard.PHP(139): Illuminate\Database\Eloquent\Model->__call('withAccessToken',Array)
#7 /home/portalvarius/app/production/vendor/laravel/passport/src/Guards/TokenGuard.PHP(139): App\Models\User->withAccessToken(Object(Laravel\Passport\Token))
#8 /home/portalvarius/app/production/vendor/laravel/passport/src/Guards/TokenGuard.PHP(90): Laravel\Passport\Guards\TokenGuard->authenticateViaBearerToken(Object(Illuminate\Http\Request))
#9 /home/portalvarius/app/production/vendor/laravel/passport/src/PassportServiceProvider.PHP(251): Laravel\Passport\Guards\TokenGuard->user(Object(Illuminate\Http\Request))
#10 [internal function]: Laravel\Passport\PassportServiceProvider->Laravel\Passport\{closure}(Object(Illuminate\Http\Request))
#11 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.PHP(53): call_user_func(Object(Closure),Object(Illuminate\Http\Request))
#12 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(544): Illuminate\Auth\RequestGuard->user()
#13 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(548): Illuminate\Auth\RequestGuard->check()
#14 /home/portalvarius/app/production/app/Http/Middleware/Authenticate.PHP(20): Illuminate\Auth\RequestGuard->guest()
#15 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10052): App\Http\Middleware\Authenticate->handle(Object(Illuminate\Http\Request),Object(Closure),'api')
#16 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.PHP(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#17 /home/portalvarius/app/production/Api/V1/Http/Middleware/LogApiAccess.PHP(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#18 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10052): Api\V1\Http\Middleware\LogApiAccess->handle(Object(Illuminate\Http\Request),Object(Closure))
#19 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.PHP(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#20 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10160): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#21 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10052): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request),Object(Closure))
#22 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.PHP(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.PHP(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#24 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10052): Illuminate\Routing\Middleware\ThrottleRequests->handle(Object(Illuminate\Http\Request),'60','1')
#25 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.PHP(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10037): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(8339): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#28 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(8330): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route),Object(Illuminate\Http\Request))
#29 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(8321): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#30 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(2575): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#31 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.PHP(53): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#32 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(3371): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#33 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10052): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request),Object(Closure))
#34 /home/portalvarius/app/production/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.PHP(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(10037): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#36 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(2519): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#37 /home/portalvarius/app/production/bootstrap/cache/compiled.PHP(2503): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#38 /home/portalvarius/app/production/public/index.PHP(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#39 {main}
好的,问题出在artisan optimize命令中.正如我在关于我的问题的评论中指出的那样,我注意到优化命令通过post-receive挂钩运行得比手动运行命令要快得多.

在我的部署环境中,我在与基本laravel目录分开的目录中有一个composer.phar文件.当我在基本目录中创建一个到composer.phar的软链接时,一切都运行正常.

我仍然不确定为什么会出现这个问题,但是看起来Laravel可能无法在从post-receive挂钩运行时找到我的作曲家实例,即使我的环境已设置为从命令行运行相同的命令精细.

猜你在找的Laravel相关文章