session_start():会话数据文件不是由您的uid创建的 [英] 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:
警告:session_start():会话数据文件不是由您的uid创建的 在第25行的/var/www/bootstrap/bootstrap.php中
Warning: session_start(): Session data file is not created by your uid in /var/www/bootstrap/bootstrap.php on line 25
警告:session_start():无法读取会话数据:文件(路径: /var/www/public/../storage/sessions/)中 /var/www/bootstrap/bootstrap.php,第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
有人可以帮助我吗?
我的服务器在PHP 7.1上运行
My server runs on PHP 7.1
推荐答案
PHP要求会话文件由运行PHP的用户拥有.
PHP requires session file to be owned by the user running PHP.
然后只需运行chown -R www-data:www-data /var/www/storage/sessions/
来由您的PHP用户拥有会话文件夹和文件(www-data:www-data
是您的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 :
).
您可以使用PHP方法get_current_user()
或在bash php -i | grep user
中运行,然后找到在其中运行PHP的用户.
You can use PHP method get_current_user()
or run in bash php -i | grep user
and find your user running PHP there.
这篇关于session_start():会话数据文件不是由您的uid创建的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!