Configuring the Directory where Session Files are Saved
Warning: You are browsing the documentation for Symfony 2.x, which is no longer maintained.
Read the updated version of this page for Symfony 7.1 (the current stable version).
By default, the Symfony Standard Edition uses the global php.ini
values
for session.save_handler
and session.save_path
to determine where
to store session data. This is because of the following configuration:
1 2 3 4 5
# app/config/config.yml
framework:
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
With this configuration, changing where your session metadata is stored
is entirely up to your php.ini
configuration.
However, if you have the following configuration, Symfony will store the session
data in files in the cache directory %kernel.cache_dir%/sessions
. This
means that when you clear the cache, any current sessions will also be deleted:
1 2 3
# app/config/config.yml
framework:
session: ~
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.
Tip
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 are also articles about storing sessions in a relational database or a NoSQL 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
:
1 2 3 4 5
# app/config/config.yml
framework:
session:
handler_id: session.handler.native_file
save_path: '%kernel.root_dir%/sessions'