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.

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

6 Answers 6

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' ]; 
Sign up to request clarification or add additional context in comments.

6 Comments

Yep...this actually makes sense, but added this exception and the problem persists...
@DvdEnde haha, thank you for the appreciation. Hope I saved you some time!
Don't forget to clear your cookies as @ceejayoz mentioned.
phpsessid is the cookie that I'm getting stuck on.
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.
|
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

1 Comment

This worked for me, while the accepted answer did not.
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.

Comments

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 Comment

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.
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 } ] 

}

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.