7
votes

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

9
It's a linux user permissions error; make sure your able to read/write to those locations(folders should be 0755 and your files should be 0644), and that your user has permission to read to those locations. - Kaylined
how can I find out which user wants to access those locations? and changing permissions is chown right? - Oreborous
I have tried all of the above solutions, change the folders folder, create another folder for the session, manage a session by redis, and nothing worked, which solved my problem leaving session.auto_start = 1 which means enabled, in php.ini - Jerfeson Guerreiro

9 Answers

9
votes

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.

4
votes

Editing config/config.yml and replacing save_path:

session:
    save_path: '/tmp'
4
votes

this works for me:

sudo chown -R www-data:www-data /var/lib/php/sessions 
3
votes

On Ubuntu within Windows 10 , my php user is the default user I create for the first install, I dont know why because the etc/apache2/envvars is not configured like that.

Nevermind, I change it for fix it quickly and now, it works.

export APACHE_RUN_USER=rudak
export APACHE_RUN_GROUP=rudak
2
votes

What worked for me, could work for you as well.

It looks like something went wrong with the session. Open the browser's DevTools and delete all Sessioncookies.

1
votes

I could be that your Session file was created by another user (well UID), try (re)moving the session file(s) from your temp dir something like /var/tmp

1
votes

I use this to also make Named Pipes in php.

<?php
$user = get_current_user();   // get current process user

// We need to modify the permissions so users can write to it

exec( "chown -R {$user}:{$user} $fifoPath" );    
0
votes

Another solution: rename your session folder var/session to var/session_old

create a new folder var/session

and delete the old one.

0
votes

For lampp users,
- go to /opt/lampp/temp/
- delete session file, and test again

After testing again,
If error message "Wrong permissions on configuration file, should not be world writable!" shows,
Run the following at terminal:
sudo chmod 755 /opt/lampp/phpmyadmin/config.inc.php

That worked for me ...