24

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.

2
  • 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, 2017 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? Nov 17, 2017 at 21:30

6 Answers 6

51

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'
];
6
  • 1
    Yep...this actually makes sense, but added this exception and the problem persists...
    – Dyego Nery
    Jun 29, 2018 at 17:11
  • @DvdEnde haha, thank you for the appreciation. Hope I saved you some time!
    – Jonathan
    Sep 18, 2018 at 8:14
  • 2
    Don't forget to clear your cookies as @ceejayoz mentioned.
    – pamit
    Jan 16, 2019 at 22:17
  • 1
    phpsessid is the cookie that I'm getting stuck on. Apr 9, 2019 at 14:52
  • 1
    When using vscode the cookie is set to VSCODE. Add that to your array if this still doe snot work for you. Same for other popular IDE keys afaict.
    – Daniel
    Jul 3, 2020 at 14:05
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

4
  • 1
    Thanks for the hint!
    – dns_nx
    May 8, 2019 at 18:54
  • 2
    This worked for me, while the accepted answer did not.
    – arm
    May 28, 2020 at 13:55
  • Works for me! Thanks! Jan 25, 2021 at 22:16
  • Works for me using Laradock. Thanks! Apr 8, 2021 at 14:00
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.

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.

1
  • It's certainly a hack but it helped me at least get to a point where I knew breakpoints in my code would be hit. Sep 12, 2018 at 14:24
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
    }
]

}

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.