You are browsing the documentation for Symfony 4.1 which is not maintained anymore.
Consider upgrading your projects to Symfony 5.2.
Configuring the Directory where Session Files are Saved
Configuring the Directory where Session Files are Saved¶
By default, Symfony stores session metadata on the filesystem. If you want to control
this path, update the framework.session.save_path
configuration key:
- YAML
1 2 3 4 5
# config/packages/framework.yaml framework: session: handler_id: session.handler.native_file save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
- XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<!-- config/packages/framework.xml --> <?xml version="1.0" encoding="UTF-8" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:framework="http://symfony.com/schema/dic/symfony" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> <framework:config> <framework:session handler-id="session.handler.native_file" save-path="%kernel.project_dir%/var/sessions/%kernel.environment%" /> </framework:config> </container>
- PHP
1 2 3 4 5 6 7
// config/packages/framework.php $container->loadFromExtension('framework', [ 'session' => [ 'handler_id' => 'session.handler.native_file', 'save_path' => '%kernel.project_dir%/var/sessions/%kernel.environment%' ], ]);
Storing Sessions Elsewhere (e.g. database)¶
You can store your session data anywhere by using the handler_id
option.
See Configuring Sessions and Save Handlers for a discussion of
session save handlers. There are also articles about storing sessions in a
relational database
or a NoSQL database.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.