WARNING: You are browsing the documentation for Symfony 2.1 which is not maintained anymore. Consider upgrading your projects to Symfony 4.0.

Configuring the Directory where Sessions Files are Saved

2.1 version
Unmaintained

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.

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 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
    1
    2
    3
    4
    # app/config/config.yml
    framework:
        session:
            save_path: "%kernel.root_dir%/sessions"
    
  • XML
    1
    2
    3
    4
    <!-- app/config/config.xml -->
    <framework:config>
        <framework:session save-path="%kernel.root_dir%/sessions" />
    </framework:config>
    
  • PHP
    1
    2
    3
    4
    // app/config/config.php
    $container->loadFromExtension('framework', array(
        'session' => array('save-path' => "%kernel.root_dir%/sessions"),
    ));
    

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.