Configuring the Directory where Sessions Files are Saved

Edit this page

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

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

Configuring the Directory where Sessions Files are Saved

By default, Symfony stores the session data in the cache directory. This means that when you clear the cache, any current sessions will also be deleted.

Using a different directory to save session data is one method to ensure that your current sessions aren't lost when you clear Symfony's cache.


Using a different session save handler is an excellent (yet more complex) method of session management available within Symfony. See Configuring Sessions and Save Handlers for a discussion of session save handlers. There is also an entry in the cookbook about storing sessions in the database.

To change the directory in which Symfony saves session data, you only need change the framework configuration. In this example, you will change the session directory to app/sessions:

  • YAML
  • XML
  • PHP
# app/config/config.yml
        save_path: "%kernel.root_dir%/sessions"
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.