Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • SensioLabs Professional services to help you with Symfony
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Cookbook
  4. Configuration
  5. How to override Symfony's Default Directory Structure
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • Override the cache directory
  • Override the logs directory
  • Override the web directory

How to override Symfony's Default Directory Structure

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).

How to override Symfony's Default Directory Structure

Symfony automatically ships with a default directory structure. You can easily override this directory structure to create your own. The default directory structure is:

1
2
3
4
5
6
7
8
9
10
11
12
app/
    cache/
    config/
    logs/
    ...
src/
    ...
vendor/
    ...
web/
    app.php
    ...

Override the cache directory

You can override the cache directory by overriding the getCacheDir method in the AppKernel class of you application:

1
2
3
4
5
6
7
8
9
10
11
12
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function getCacheDir()
    {
        return $this->rootDir.'/'.$this->environment.'/cache';
    }
}

$this->rootDir is the absolute path to the app directory and $this->environment is the current environment (i.e. dev). In this case you have changed the location of the cache directory to app/{environment}/cache.

Caution

You should keep the cache directory different for each environment, otherwise some unexpected behaviour may happen. Each environment generates its own cached config files, and so each needs its own directory to store those cache files.

Override the logs directory

Overriding the logs directory is the same as overriding the cache directory, the only difference is that you need to override the getLogDir method:

1
2
3
4
5
6
7
8
9
10
11
12
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function getLogDir()
    {
        return $this->rootDir.'/'.$this->environment.'/logs';
    }
}

Here you have changed the location of the directory to app/{environment}/logs.

Override the web directory

If you need to rename or move your web directory, the only thing you need to guarantee is that the path to the app directory is still correct in your app.php and app_dev.php front controllers. If you simply renamed the directory, you're fine. But if you moved it in some way, you may need to modify the paths inside these files:

1
2
require_once __DIR__.'/../Symfony/app/bootstrap.php.cache';
require_once __DIR__.'/../Symfony/app/AppKernel.php';

Since Symfony 2.1 (in which Composer is introduced), you also need to change the extra.symfony-web-dir option in the composer.json file:

1
2
3
4
5
6
7
{
    ...
    "extra": {
        ...
        "symfony-web-dir": "my_new_web_dir"
    }
}

Tip

Some shared hosts have a public_html web directory root. Renaming your web directory from web to public_html is one way to make your Symfony project work on your shared host. Another way is to deploy your application to a directory outside of your web root, delete your public_html directory, and then replace it with a symbolic link to the web in your project.

Note

If you use the AsseticBundle you need to configure this, so it can use the correct web directory:

  • YAML
  • XML
  • PHP
1
2
3
4
5
6
# app/config/config.yml

# ...
assetic:
    # ...
    read_from: "%kernel.root_dir%/../../public_html"
1
2
3
4
<!-- app/config/config.xml -->

<!-- ... -->
<assetic:config read-from="%kernel.root_dir%/../../public_html" />
1
2
3
4
5
6
7
// app/config/config.php

// ...
$container->loadFromExtension('assetic', array(
    // ...
    'read_from' => '%kernel.root_dir%/../../public_html',
));

Now you just need to dump the assets again and your application should work:

1
$ php app/console assetic:dump --env=prod --no-debug
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Become certified from home

    Become certified from home

    Measure & Improve Symfony Code Performance

    Measure & Improve Symfony Code Performance

    Symfony footer

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

    Avatar of Mátyás Somfai, a Symfony contributor

    Thanks Mátyás Somfai (@smatyas) for being a Symfony contributor

    5 commits • 638 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