Configuring the Directory where Session Files are Saved

Edit this page

Warning: You are browsing the documentation for Symfony 4.0, which is no longer maintained.

Read the updated version of this page for Symfony 6.1 (the current stable version).

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
# config/packages/framework.yaml
        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.