我正在Ubuntu14.04、PHP7.1和Apache2.4.23栈上运行Symfony 3.1.5,这些堆栈由Vagrant1.8.6/VirtualBox 5.1.6管理。我试图使用一个简单的控制器在我的前端做出响应:
<?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!');
}
}当我试图通过/app_dev.php访问我的Symfony前端时,我看到:
Warning: SessionHandler::read(): Session data file is not created by your uid 500 Internal Server Error - ContextErrorException
我的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
Symfony dev日志如下:
==> /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)"} []
鉴于这似乎是与会话相关的问题,我参考了Session Management的Symfony文档。它指出:
Symfony会话与php.ini指令session.auto_start =1不兼容,应该在php.ini、off服务器指令或.htaccess中关闭该指令。
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
我尝试根据Symfony文档中的说明创建一个.htaccess (我把它放在DocumentRoot中),但是错误仍然存在。
我已经搜索了几个线程和问题,以找到一个解决方案,但没有发现任何东西。有什么原因吗?
发布于 2016-10-11 18:23:41
编辑config/config.yml并将save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"替换为save_path: /var/lib/php/sessions修复了错误。
如果使用自动将空格转换为制表符的编辑器/IDE,请确保在保存更改之前禁用该功能。如果不这样做,可能会导致“不包含有效的YAML”错误。
发布于 2016-12-03 17:47:16
我也有同样的问题。对我起作用的修复方法是将var/sessions所有者更改为www-data:www-data (php子进程的相同用户/组):
sudo chown -R www-data:www-data var/sessions/发布于 2017-08-31 15:24:33
避免更改只发生在开发环境中的故障的产品配置。
在使用同步文件夹时(PHP 7+ Nginx) (/vagrant ~ default),也有同样的问题。
解决了刚刚放
session:
save_path: '/tmp'config_dev.yml在框架条目中的应用
只需选择一些地方,can服务器和PHP可以在没有权限问题的情况下进行读写。
https://stackoverflow.com/questions/39980171
复制相似问题