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
621 views
in Technique[技术] by (71.8m points)

php - Symfony 3.1.5 Warning: SessionHandler::read(): Session data file is not created by your uid

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:

<?php

namespace AppBundleController;

use SensioBundleFrameworkExtraBundleConfigurationRoute;
use SymfonyComponentBrowserKitResponse;

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:

Warning: SessionHandler::read(): Session data file is not created by your uid 500 Internal Server Error - ContextErrorException

My Apache log reads:

CRITICAL - Uncaught PHP Exception SymfonyComponentDebugExceptionContextErrorException: "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:

==> /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 SymfonyComponentDebugExceptionContextErrorException: "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:

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.

session.auto_start = 0 in my php.ini and the file is owned by user and group 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

I've tried creating an .htaccess (which I placed in my DocumentRoot) per the instructions in the Symfony documentation, but the error persists.

I've searched several threads and questions for a solution but have not landed on anything. Any ideas what is causing this?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.

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.


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

...