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

Medala's avatar
Level 12

Session works on local machine but having trouble in production

Both Server and Production are on Laravel 6, PHP 7.3, Session Driver: file

I store item in a cart using session: ProductController:

public function axiosAddQuantity(Request $request)
    {
        
        $input = $request->all();
        $product = Product::find($input['item']['id']);
        //$oldCart = session()->has('cart') ? session()->get('cart') : null;

        $oldCart = null;
        if(session()->has('cart'))
        {
            $oldCart = session()->get('cart');
        }

        $cart = new Cart($oldCart);

        $quantity = $input['item']['quantity'];
        $cart->addQuanitity($product, $product->id, $quantity);

        $request->session()->put('cart', $cart);
    

        return redirect()->back();
    }

The above method works only on local machine, but it does not work on the server. The data is submitted using axios, I have tried it without axios and got the same problem on the server. The sessions file are created on the server but no idead why it can't pick up the right session file.

Session works on the server if I store and get it in the same method.

0 likes
4 replies
jlrdw's avatar

Make sure storage folder has correct permissions.

Medala's avatar
Level 12

This is the current permission on the Storage folder, What do I change it to?

drwxrwxr-x  5 forge forge   4096 Feb 23 08:22  storage
Medala's avatar
Level 12

I guess I need to set it to drwxrwxrwx, to have a write permission, correct?

Medala's avatar
Medala
OP
Best Answer
Level 12

Solved, Not a server issue, it was my JavaScript.

Please or to participate in this conversation.