Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session_start(): Session data file is not created by your uid

Tags:

php

session

I want to store the created sessions in a directory above the root, except when I use any of the following:

    session_save_path($_SERVER['DOCUMENT_ROOT'] . '/../storage/sessions');
    session_save_path($_SERVER['DOCUMENT_ROOT'] . '/../storage/sessions/'); // With an extra slash at the end
ini_set('session.save_path', $_SERVER['DOCUMENT_ROOT'] . '/../storage/sessions');
ini_set('session.save_path', $_SERVER['DOCUMENT_ROOT'] . '/../storage/sessions/'); // Again with the extra slash

and not one of these methods work, whenever I load the page I get the following errors:

Warning: session_start(): Session data file is not created by your uid in /var/www/bootstrap/bootstrap.php on line 25

Warning: session_start(): Failed to read session data: files (path: /var/www/public/../storage/sessions/) in /var/www/bootstrap/bootstrap.php on line 25

Can anyone help me?

Edit: My server runs on PHP 7.1

like image 702
Oreborous Avatar asked Jan 20 '17 19:01

Oreborous


2 Answers

PHP requires session file to be owned by the user running PHP.

Then just run chown -R www-data:www-data /var/www/storage/sessions/ to own session folder and files by your PHP user (www-data:www-data are your PHP user and group separated by :).

You can use PHP method get_current_user() or run in bash php -i | grep user and find your user running PHP there.

like image 185
zored Avatar answered Oct 13 '22 19:10

zored


Editing config/config.yml and replacing save_path:

session:
    save_path: '/tmp'
like image 4
Ashfaq Muhammad Avatar answered Oct 13 '22 19:10

Ashfaq Muhammad