25

I configured Xdebug on VScode to debug my laravel application. But, when I start to debug, laravel always throws this error: Exception has occurred. Illuminate\Contracts\Encryption\DecryptException: The payload is invalid.

I already tried to run php artisan optimize.

Anyone here already faced this issue? I'm using Laravel 5.5

Ps. I tried to debug a Laravel 4 application. It worked without any issues. So, I think it may be something specific for Laravel 5.

Dyego Nery
  • 424
  • 1
  • 4
  • 8
  • 3
    Try clearing out all your cookies. Unless you're specifically doing something with encryption/decryption in your site's code, it sounds like one of your Laravel cookies is encrypted with the wrong APP_KEY value. – ceejayoz Nov 17 '17 at 17:01
  • 1
    Same issue here. I've cleared my cookies, run php artisan optimize, and continue to get the same error. Restarted the box too. Debug works in PHPStorm, so I'll go out on a limb and say it's configured properly in my vagrant / homestead box. Really strange, and I know its going to be something silly when I figure it out. Are you using a browser plug-in like Xdebug helper? – Jonathan Wheat Nov 17 '17 at 21:30

6 Answers6

52

By default Laravel will encrypt, and subsequently also decrypt, all cookies on a request.

When using Xdebug to debug your application from a browser, a cookie called "XDEBUG_SESSION" is set. As this cookie was not set, and thus not encrypted, by the Laravel framework, an error will be thrown when the framework automatically detects and tries to decrypt the cookie.

The correct solution is to just add the "XDEBUG_SESSION" cookie to the exceptions array in the App\Http\Middleware\EncryptCookies middleware.

/**
 * The names of the cookies that should not be encrypted.
 *
 * @var array
 */
protected $except = [
    'XDEBUG_SESSION'
];
Jonathan
  • 1,041
  • 1
  • 12
  • 21
18

If the answer doesn't work, try adding this into launch.json

{
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9001,
        "ignore": [
            "**/vendor/**/*.php"
        ]
    },

More info: https://stackoverflow.com/a/49795318/1998033

Vrutin Rathod
  • 900
  • 1
  • 12
  • 16
2

The @ceejayoz comment solved the issue. I run php artisan otimize, and the clear all my cookies on the browser, and it started to work properly.

Dyego Nery
  • 424
  • 1
  • 4
  • 8
1

As far as I am concerned, I also had to turn off the Exceptions and Everything from being reported, or else, the issue persisted.

HAVB
  • 1,858
  • 1
  • 22
  • 37
bdebever
  • 21
  • 1
0

This my solution. I'm using VsCode and the file configuration xdebug (launch.json) must be match to workspace

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "log":true,
        "pathMappings": {

           // "serverSourceRoot": "/var/www/html",
            //"localSourceRoot": "${workspaceRoot}"
            "/var/www/html":"/Users/{username}/sites/{mysitefolder}"

        },
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

Efrén
  • 417
  • 5
  • 7
0

Temporarily commented out \App\Http\Middleware\EncryptCookies::class, which is inside of the web middlewareGroups of app/Http/Kernel. Solved my issue with this. Do need to remember turn it back though. Any better solutions from anyone? I tried the above mentioned methods, no one worked for me, unfortunately.

Homer
  • 449
  • 4
  • 9