Deploying a Laravel application terminates the application until the composer installation is started manually

I have a Laravel application using Passport to provide API authentication. The application is deployed using git with a hook after receiving. Part of the post-receive script is the installation of the composer. Since I turned on Passport, whenever I deploy my application, the API breaks on the routes that are behind the authentication shutter, and the stack trace is lower.

When I go to the application server and run the same composer install command as in my post-receive method, then everything works fine.

I do not see error messages from git when the deployment occurs, and it seems that I get the same output from composer install when the deployment occurs, and when I run the command manually.

Here the output of the composer install command is expanded:

 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 

And this is what I see when I run the command manually:

 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 

What's going on here? Deployment seems to install an older version of some Passport component, which is then fixed after running composer install manually, but I don’t understand why this will happen, and especially why it will happen every time I deploy a new update, even if there are no changes to composer.json or composer.lock.

Here's the stack trace mentioned above:

 [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), Object(Closure), '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} 
+8
githooks laravel composer-php
source share
1 answer

So, the problem was with the optimizer team. As I pointed out in the commentary on my question, I noticed that the optimize command starts much faster than when manually running the command.

In my deployed environment, I have a composer.phar file in a directory separate from the laravel base directory. When I made softlink for composer.phar in the base directory, everything worked fine again.

I'm still not sure why the problem occurred, but it looks like Laravel might not be able to find my linker instance when starting from hook after submitting, although my environment was set up so that the same command started from the command line worked fine .

+3
source share

All Articles