onieyanihh's avatar

419 | Page Expired error.

Hi. I have live server website made with Laravel 9 and its working perfectly.

Then one day i cleared the config of my website using php artisan route:clear, view:clear, etc.. After that, i've got 419 | Page Expired Error.

I searched for an answer before posting here but none of them works.

Then I downloaded my project and tried it on my localhost and ITS WORKING perfectly. I dont know why on my live server its not working and in my localhost its working.

Can anyone help me? Thank you!

0 likes
15 replies
jlrdw's avatar

See if your session still works, set a session var, go to another page and read the session var. But this sounds like a cache problem, clear your cache folders also. Meaning everything in the bootstrap/cache folder except .gitignore. Don't delete .gitignore.

onieyanihh's avatar

@jlrdw i will delete everything except for .gitignore in bootstrap cache? am i right?

onieyanihh's avatar

    public function setSession(Request $request)
    {
           $request->session()->put('name', 'John');

    		return redirect('/read-session');
    }

    public function readSession(Request $request)
    {
          $name = $request->session()->get('name');

   		 return view('read-session', compact('name'));
    }

view

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Read Session</title>
</head>
<body>
    <h1>Your name is {{ $name }}</h1>
</body>
</html>

web.php

Route::get('/set-session', [UserController::class,'setSession']);
Route::get('/read-session', [UserController::class,'readSession']);

output: NONE (did not fetched the $name.) https://prnt.sc/aGkOWp7ifRHZ

JussiMannisto's avatar

Did you run those artisan command as some user other than the web server user? This can change the file and directory permissions under storage/framework. If you're using file-based sessions, the framework may then not be able to write session files (although I'd expect this to cause an exception rather than silently fail).

Check the permissions of storage/framework and its subdirectories, and make sure they are owned by the web server user.

onieyanihh's avatar

@JussiMannisto

i run the commands using cpanel terminal. i also checked the permissions of my storage/framework all folders' permission was set to 0755 and all file's permissions were set to 0644

JussiMannisto's avatar

@onieyanihh And who is the owner of those files & directories? What matters here is the directory storage/framework/sessions and its files.

JussiMannisto's avatar

@onieyanihh I haven't used cPanel in ages, but running ls -l -d storage/framework/sessions/ in the terminal should work. Run that in your project root and show the output.

I'm sure you can check the directory owner through cPanel in other ways too.

JussiMannisto's avatar

@onieyanihh I can't make out the user since you covered it, but I assume that's your username? If so, that's the issue. The web server user doesn't have write permissions to the directory, and cannot create session files.

You need to change the owner and group of the storage directory and its contents. You can do this through the terminal by running sudo chown username:groupname -R storage/. Just replace the username and groupname with the user and group names of the web server user.

onieyanihh's avatar

@JussiMannisto user is not in the sudoers file. This incident will be reported.

Im getting an error using this sudo chown username:groupname -R storage/

JussiMannisto's avatar

@onieyanihh So you don't have sudo privileges? You need them to change the ownership of a directory. Your user needs to be in the wheel group, or you need to login as the root user.

The username:groupname part was just an example. You have to replace those with the correct values, e.g. apache:apache or nginx:nginx, depending on your server setup.

1 like
Adeodatus's avatar

For me, in the migration file that creates the sessions table (0001_01_01_000000_create_sessions_table.php), the default data type for the id column is a string, because Laravel stores session IDs as strings. Somehow, I changed that id column to an integer, which caused Laravel to fail fetching the proper session details. As a result, every form submission triggered the "Page Expired" error.

PS: This applies when using the database as the session driver.

Please or to participate in this conversation.