简体   繁体   English

Laravel 5.3不通过Apache保存会话

[英]Laravel 5.3 not saving sessions via apache

I am getting a CSRF Token mismatch but that is not the underlying issue. 我遇到CSRF令牌不匹配的问题,但这不是根本问题。 When I add an exception to the page I get a 500 error. 将异常添加到页面时,出现500错误。

I have found that this is being caused by a problem creating sessions. 我发现这是由创建会话的问题引起的。

When I serve everything works fine. 当我服务时,一切正常。 When I put it into production it fails to create the sessions. 当我将其投入生产时,它无法创建会话。

Has anyone experienced this issue before? 有人遇到过这个问题吗?

Error I am receiving: 我收到的错误:

1/1
TokenMismatchException in VerifyCsrfToken.php line 68:
in VerifyCsrfToken.php line 68
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 655
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53

Then I add the login route to the CSRF exceptions and I get a 500 error. 然后,我将登录路由添加到CSRF异常中,并出现500错误。

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        //
        '/login/',
    ];
}

Google chrome error message: Google Chrome错误消息:

This page isn’t working

'address' is currently unable to handle this request.
HTTP ERROR 500

Running CentOS 7.0 and SElinux was preventing the apache user from writing to storage. 运行CentOS 7.0和SElinux会阻止apache用户写入存储。 Even if you have chmod 777 set for this directory it will not allow you to write to the storage directory. 即使为该目录设置了chmod 777,它也不允许您写入存储目录。

The storage folder is where your sessions are stored so it throws a csrf token mismatch because it has nothing to compare to with session variables shut off. 存储文件夹是您的会话存储的位置,因此它抛出csrf令牌不匹配,因为它与关闭会话变量没有什么可比性。

I want to stress that this is a configuration issue not a laravel issue. 我想强调,这是一个配置问题,而不是Laravel问题。 I searched far and wide on the internet and this is what finally solved my issue. 我在互联网上四处搜寻,这终于解决了我的问题。

setenforce 0

This should allow writing, but you've turned off added security server-wide. 这应该允许写入,但是您已关闭了服务器范围内添加的安全性。 That's bad. 那很糟。 Turn SELinux back 退回SELinux

setenforce 1

Then finally use SELinux to allow writing of the file by using this command from the project root directory. 然后,最后使用SELinux通过从项目根目录使用此命令来写入文件。

chcon -R -t httpd_sys_rw_content_t storage

I want to thank everyone in the comments section your line of questioning got me on the right track to a solution! 我要感谢评论部分中的每个人,您的疑问使我走上了正确的解决之路!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM