Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Cookbook
  4. Session
  5. Configuring the Directory where Sessions Files are Saved
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Configuring the Directory where Sessions Files are Saved

Edit this page

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

Read the updated version of this page for Symfony 6.2 (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.

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
  • XML
  • PHP
1
2
3
4
# app/config/config.yml
framework:
    session:
        save_path: "%kernel.root_dir%/sessions"
1
2
3
4
<!-- app/config/config.xml -->
<framework:config>
    <framework:session save-path="%kernel.root_dir%/sessions" />
</framework:config>
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.
We stand with Ukraine.
Version:
Show your Symfony expertise

Show your Symfony expertise

Measure & Improve Symfony Code Performance

Measure & Improve Symfony Code Performance

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Jordan de Laune, a Symfony contributor

Thanks Jordan de Laune (@jdelaune) for being a Symfony contributor

4 commits • 28 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia