php session_start(): 会话数据文件不是由你的 uid 创建的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41771425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:28:02  来源:igfitidea点击:

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

phpsession

提问by Oreborous

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

警告:session_start():会话数据文件不是由您在第 25 行的 /var/www/bootstrap/bootstrap.php 中的 uid 创建的

警告:session_start():无法读取会话数据:第 25 行 /var/www/bootstrap/bootstrap.php 中的文件(路径:/var/www/public/../storage/sessions/)

Can anyone help me?

谁能帮我?

Edit:My server runs on PHP 7.1

编辑:我的服务器在 PHP 7.1 上运行

回答by zored

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

PHP 要求会话文件归运行 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-dataare your PHP user and group separated by :).

然后只需运行chown -R www-data:www-data /var/www/storage/sessions/您的 PHP 用户自己的会话文件夹和文件(www-data:www-data您的 PHP 用户和组是否由 分隔:)。

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

您可以使用 PHP 方法get_current_user()或在 bash 中运行并在php -i | grep user那里找到运行 PHP 的用户。

回答by Ashfaq Muhammad

Editing config/config.ymland replacing save_path:

编辑config/config.yml并替换 save_path:

session:
    save_path: '/tmp'

回答by elMatador

this works for me:

这对我有用:

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

回答by rudak

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/envvarsis not configured like that.

在 Windows 10 中的 Ubuntu 上,我的 php 用户是我为第一次安装创建的默认用户,我不知道为什么,因为etc/apache2/envvars没有这样配置。

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

没关系,我更改它以快速修复它,现在它可以工作了。

export APACHE_RUN_USER=rudak
export APACHE_RUN_GROUP=rudak

回答by Florin

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.

会话好像出了点问题。打开浏览器的 DevTools 并删除所有 Sessioncookie。

回答by Recycled Steel

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

我可能是您的会话文件是由另一个用户(以及 UID)创建的,请尝试(重新)从您的临时目录中移动会话文件,例如 /var/tmp

回答by Tyler Miles

I use this to also make Named Pipesin php.

我也用它来在 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" );    

回答by Martijn van Hoof

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

另一种解决方案:将您的会话文件夹 var/session 重命名为 var/session_old

create a new folder var/session

创建一个新文件夹 var/session

and delete the old one.

并删除旧的。

回答by Nooovice Boooy

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

对于lampp用户,
- 转到 /opt/lampp/temp/
- 删除会话文件,然后再次测试

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

再次测试后,
如果错误信息“配置文件的权限错误,不应该是全局可写的!” 显示,
在终端运行以下命令:
sudo chmod 755 /opt/lampp/phpmyadmin/config.inc.php

That worked for me ...

那对我有用...