Configuring the Directory where Session Files are Saved

Version: 4.0
Edit this page

Warning: You are browsing the documentation for version 4.0 which is not maintained anymore.

If some of your projects are still using this version, consider upgrading.

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
  • XML
  • PHP
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%'

Storing Sessions Elsewhere (e.g. database)

Of course, 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.