Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amostajo's avatar

Session cookie not being created

Hello!

I'm having this weird issue in localhost where session cookies is not being created.

This happened after we launched the app live; in order to do this, I had to change the public path from public to public_html and I had to add this to AppServiceProvider.php register() function:

    $this->app->bind('path.public', function() {
        return base_path() . '/public_html';
    });

Server side everything is working fine but in localhost for some reason Laravel stopped creating the session cookie and because of this I'm having the TokenMismatchException (CSRF) validation error in my POST requests.

Any hint or suggesrion?

0 likes
4 replies
BrianVeltman's avatar

You may need to set a conditional for the code above. I assume that you don't have a public_html on your local host.

amostajo's avatar

public has been renamed to public_html, localhost issues started after this switch.

BrianVeltman's avatar

That make sense.

I'm not that familiar with the core of laravel but in this case I would rename the public folder on the production server to public_html and on the local host just leave it as public.

Then update the code to this:

if ($this->app->environment() != 'local') {
            $this->app->bind('path.public', function() {
            return base_path() . '/public_html';
        });
     }
amostajo's avatar
amostajo
OP
Best Answer
Level 1

Solved the issue.

We had setup PERCH CMS with laravel. The issue was caused by Perch, it was echoing stuff before laravel could send headers and init the session. After we fixed this, session cookies were restored to normal behavior.

Thanks for your hints.

Please or to participate in this conversation.