php Symfony 3.1.5 警告:SessionHandler::read():会话数据文件不是由您的 uid 创建的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39980171/
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
Symfony 3.1.5 Warning: SessionHandler::read(): Session data file is not created by your uid
提问by marcusnjones
I'm running Symfony 3.1.5 on a Ubuntu 14.04, PHP 7.1 and Apache 2.4.23 stack managed by Vagrant 1.8.6/VirtualBox 5.1.6. I'm trying to use a simple controller I've made to render a response on my frontend:
我在 Vagrant 1.8.6/VirtualBox 5.1.6 管理的 Ubuntu 14.04、PHP 7.1 和 Apache 2.4.23 堆栈上运行 Symfony 3.1.5。我正在尝试使用一个简单的控制器来在我的前端呈现响应:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\BrowserKit\Response;
class LandingController {
/**
* @Route("/", name="homepage")
*/
public function showAction(){
return new Response('This is the landing page!');
}
}
When I attempt to access my Symfony frontend via /app_dev.php
I see:
当我尝试通过以下方式访问我的 Symfony 前端时/app_dev.php
:
Warning: SessionHandler::read(): Session data file is not created by your uid
500 Internal Server Error - ContextErrorException
Warning: SessionHandler::read(): Session data file is not created by your uid
500 Internal Server Error - ContextErrorException
My Apache log reads:
我的 Apache 日志显示:
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: SessionHandler::read(): Session data file is not created by your uid" at /var/www/conan/var/cache/dev/classes.php line 366
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: SessionHandler::read(): Session data file is not created by your uid" at /var/www/conan/var/cache/dev/classes.php line 366
The Symfony dev log reads:
Symfony 开发日志显示:
==> /var/www/conan/var/logs/dev.log <==
[2016-10-11 14:23:04] request.INFO: Matched route "{route}". {"route":"homepage","route_parameters":{"_controller":"AppBundle\\Controller\\LandingController::showAction","_route":"homepage"},"request_uri":"http://conan.dev/app_dev.php/","method":"GET"} []
[2016-10-11 14:23:04] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: SessionHandler::read(): Session data file is not created by your uid" at /var/www/conan/var/cache/dev/classes.php line 366 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Warning: SessionHandler::read(): Session data file is not created by your uid at /var/www/conan/var/cache/dev/classes.php:366)"} []
==> /var/www/conan/var/logs/dev.log <==
[2016-10-11 14:23:04] request.INFO: Matched route "{route}". {"route":"homepage","route_parameters":{"_controller":"AppBundle\\Controller\\LandingController::showAction","_route":"homepage"},"request_uri":"http://conan.dev/app_dev.php/","method":"GET"} []
[2016-10-11 14:23:04] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: SessionHandler::read(): Session data file is not created by your uid" at /var/www/conan/var/cache/dev/classes.php line 366 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Warning: SessionHandler::read(): Session data file is not created by your uid at /var/www/conan/var/cache/dev/classes.php:366)"} []
Seeing as this appears to be a session related issue, I've referred to the Symfony documentation for Session Management. It states:
看到这似乎是一个与会话相关的问题,我参考了Session Management的 Symfony 文档。它指出:
Symfony sessions are incompatible with php.ini directive session.auto_start = 1 This directive should be turned off in php.ini, in the webserver directives or in .htaccess.
Symfony 会话与 php.ini 指令不兼容 session.auto_start = 1 该指令应该在 php.ini、webserver 指令或 .htaccess 中关闭。
session.auto_start = 0
in my php.ini
and the file is owned by user and group root
:
session.auto_start = 0
在我php.ini
的文件中,该文件归用户和组所有root
:
$ ls -lta /etc/php/7.1/fpm/php.ini
-rw-r--r-- 1 root root 70584 Sep 30 07:29 /etc/php/7.1/fpm/php.ini
$ ls -lta /etc/php/7.1/fpm/php.ini
-rw-r--r-- 1 root root 70584 Sep 30 07:29 /etc/php/7.1/fpm/php.ini
I've tried creating an .htaccess
(which I placed in my DocumentRoot
) per the instructions in the Symfony documentation, but the error persists.
我已经尝试按照 Symfony 文档中的说明创建一个.htaccess
(我放在我的 中DocumentRoot
),但错误仍然存在。
I've searched several threads and questions for a solution but have not landed on anything. Any ideas what is causing this?
我搜索了几个线程和问题以寻求解决方案,但没有找到任何解决方案。任何想法是什么导致了这种情况?
回答by marcusnjones
Editing config/config.yml
and replacing save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
with save_path: /var/lib/php/sessions
fixed the error.
编辑config/config.yml
和更换save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
有save_path: /var/lib/php/sessions
固定的错误。
If you use an editor/IDE that automatically converts spaces to tabs, be sure to disable that feature before saving your changes. Failure to do so may cause a 'does not contain valid YAML' error to occur.
如果您使用自动将空格转换为制表符的编辑器/IDE,请确保在保存更改之前禁用该功能。不这样做可能会导致“不包含有效的 YAML”错误发生。
回答by Takman
I had the same problem. The fix that worked for me is to change var/sessions
owner to www-data:www-data
(same user/group for php-fpm sub-processes) :
我有同样的问题。对我有用的修复方法是将var/sessions
所有者更改为www-data:www-data
(php-fpm 子进程的相同用户/组):
sudo chown -R www-data:www-data var/sessions/
回答by Marcos Regis
AVOID change prod configuration for troubles that only occurs in development environment
避免因仅在开发环境中出现的问题而更改 prod 配置
Had the Same trouble when using Vagrant (PHP-FPM 7 + Nginx) with a sync folder (/vagrant ~ default)
将 Vagrant (PHP-FPM 7 + Nginx) 与同步文件夹(/vagrant ~ 默认)一起使用时遇到同样的问题
Solved just put
解决了就放
session:
save_path: '/tmp'
on config_dev.ymlinside frameworkentry
在框架条目内的config_dev.yml 上
Just choose some place that Webserver and PHP can read/write without permission issues.
只需选择 Webserver 和 PHP 可以在没有权限问题的情况下读/写的地方。
回答by Vinith
If Magento 2generates this warning,
如果Magento 2生成此警告,
Just deletealready existed session inside var/session
folder and its fixed.
只需删除var/session
文件夹内已经存在的会话及其固定的.
回答by Jesus Rodriguez
I had a similar problem and clearing my browser's cache and stored data solved the problem.
我有一个类似的问题,清除浏览器的缓存和存储的数据解决了这个问题。
On chrome and opera you should the following:
在 chrome 和 opera 上,您应该执行以下操作:
Developer tools > Application > Clear Storage > Clear Site Data
回答by Shahzaib Hayat Khan
In my case, *removing browser cookies fixed the issue. I didn't do any of the step mentioned above and tried to change permissions and all but no that wasn't the problem. I've faced problem on magento.
就我而言,*删除浏览器 cookie 解决了这个问题。我没有执行上面提到的任何步骤并尝试更改权限,但所有这些都不是问题。我在 magento 上遇到了问题。
回答by D Hersch
Session path can't be written to since the web user and the owner of the content in the sessions folder are different and thus doesn't .
无法写入会话路径,因为 Web 用户和会话文件夹中内容的所有者不同,因此不会写入。
Solution is to set your /var or /var/sessions/ ownership to the web user.
解决方案是将您的 /var 或 /var/sessions/ 所有权设置为网络用户。
chown apache:apache /var/ -R * Or: chown www-data:www-data /var/ -R *
chown apache:apache /var/ -R * 或:chown www-data:www-data /var/ -R *
Highest rated response is not really the best response here.
最高评价的反应在这里并不是最好的反应。
回答by Olivier '?lbaum' Scherler
If you are using NFS for the synced folder, then the UID and GID of all files in it will be the UID and GID of the hostuser running Vagrant, and might not match the UID and GID of the vagrant
user on the guest. For example, I have:
如果您对同步文件夹使用 NFS,那么其中所有文件的 UID 和 GID 将是运行 Vagrant的主机用户的 UID 和 GID ,并且可能与vagrant
来宾上用户的 UID 和 GID 不匹配。例如,我有:
-rw-r--r-- 1 501 dialout 5.1K Oct 29 15:14 Vagrantfile
501
is the UID of my user on the Mac, and there is no corresponding user on the guest. dialout
is the group on the guest that matches the staff
group that's my primary group on the Mac.
501
是我用户在Mac上的UID,guest上没有对应的用户。dialout
是来宾上与staff
我在 Mac 上的主要组匹配的组。
Although you have permissions to read and write all files in the synced folder, when PHP checks the UID of the session file owner, it doesn't match the user PHP is running as, and it blocks the access as a security measure.
尽管您有权读取和写入同步文件夹中的所有文件,但当 PHP 检查会话文件所有者的 UID 时,它与运行 PHP 的用户不匹配,并且它会阻止访问作为安全措施。
You can use the vagrant-bindfs
plugin to work around this:
您可以使用该vagrant-bindfs
插件来解决此问题:
vagrant-bindfs
A Vagrant plugin to automate bindfs mount in the VM. This allow you to change owner, group and permissions on files and, for example, work around NFS share permissions issues.
流浪者绑定
一个 Vagrant 插件,用于在 VM 中自动安装 bindfs。这允许您更改文件的所有者、组和权限,例如,解决 NFS 共享权限问题。
Here's what worked for me:
以下是对我有用的内容:
- Run
vagrant plugin install vagrant-bindfs
In your Vagrantfile:
config.vm.synced_folder '.', '/vagrant', disabled: true config.vm.synced_folder '.', '/vagrant-nfs', type: 'nfs' config.bindfs.bind_folder '/vagrant-nfs', '/vagrant'
Run
vagrant reload
- 跑
vagrant plugin install vagrant-bindfs
在你的 Vagrantfile 中:
config.vm.synced_folder '.', '/vagrant', disabled: true config.vm.synced_folder '.', '/vagrant-nfs', type: 'nfs' config.bindfs.bind_folder '/vagrant-nfs', '/vagrant'
跑
vagrant reload
And it works:
它有效:
-rw-r--r-- 1 vagrant vagrant 5.1K Oct 29 15:45 Vagrantfile
回答by sh6210
In my case, i was using sysfony 2 and after removing the cache the problem was gone.
就我而言,我使用的是 sysfony 2,删除缓存后问题就消失了。
rm -rf /app/cache/*
回答by Faiyaz Alam
I am using PIMCORE which is based on symfony 3. To fix this issue,I just cleared browser cache.
我正在使用基于 symfony 3 的 PIMCORE。为了解决这个问题,我刚刚清除了浏览器缓存。
I hope this will help.
我希望这将有所帮助。