Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...