Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • 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
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Reference
  4. Configuring in the Kernel (e.g. AppKernel)

Configuring in the Kernel (e.g. AppKernel)

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

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

Some configuration can be done on the kernel class itself (usually called app/AppKernel.php). You can do this by overriding specific methods in the parent Kernel class.

Configuration

  • Charset
  • Kernel Name
  • Root Directory
  • Cache Directory
  • Log Directory
  • Container Build Time

Charset

type: string default: UTF-8

This option defines the charset that is used in the application. This value is exposed via the kernel.charset configuration parameter and the getCharset() method.

To change this value, override the getCharset() method and return another charset:

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

// ...
class AppKernel extends Kernel
{
    public function getCharset()
    {
        return 'ISO-8859-1';
    }
}

Kernel Name

type: string default: app (i.e. the directory name holding the kernel class)

The name of the kernel isn't usually directly important - it's used in the generation of cache files. If you have an application with multiple kernels, the easiest way to make each have a unique name is to duplicate the app directory and rename it to something else (e.g. foo).

This value is exposed via the kernel.name configuration parameter and the getName() method.

To change this setting, override the getName() method. Alternatively, move your kernel into a different directory. For example, if you moved the kernel into a foo directory (instead of app), the kernel name will be foo.

Root Directory

3.3

The getRootDir() method is deprecated since Symfony 3.3. Use the new getProjectDir() method instead.

type: string default: the directory of AppKernel

This returns the absolute path of the directory where your kernel class is located. If you use the Symfony Standard edition, this is the app/ directory of your project.

This value is exposed via the kernel.root_dir configuration parameter and the getRootDir() method. To change this setting, override the getRootDir() method:

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

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

    public function getRootDir()
    {
        return realpath(parent::getRootDir().'/../');
    }
}

Project Directory

3.3

The getProjectDir() method was introduced in Symfony 3.3.

type: string default: the directory of the project composer.json

This returns the absolute path of the root directory of your Symfony project. It's calculated automatically as the directory where the main composer.json file is stored.

This value is exposed via the kernel.project_dir configuration parameter and the getProjectDir() method. To change this setting, override the getProjectDir() method to return the right project directory:

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

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

    public function getProjectDir()
    {
        return realpath(__DIR__.'/../');
    }
}

Cache Directory

type: string default: $this->rootDir/cache/$this->environment

This returns the absolute path of the cache directory of your Symfony project. It's calculated automatically based on the current environment.

This value is exposed via the kernel.cache_dir configuration parameter and the getCacheDir() method. To change this setting, override the getCacheDir() method to return the right cache directory.

Log Directory

type: string default: $this->rootDir/logs

This returns the absolute path of the log directory of your Symfony project. It's calculated automatically based on the current environment.

This value is exposed via the kernel.log_dir configuration parameter and the getLogDir() method. To change this setting, override the getLogDir() method to return the right log directory.

Container Build Time

type: string default: the result of executing time()

Symfony follows the reproducible builds philosophy, which ensures that the result of compiling the exact same source code doesn't produce different results. This helps checking that a given binary or executable code was compiled from some trusted source code.

In practice, the compiled service container of your application will always be the same if you don't change its source code. This is exposed via these configuration parameters:

  • container.build_hash, a hash of the contents of all your source files;
  • container.build_time, a timestamp of the moment when the container was built (the result of executing PHP's time function);
  • container.build_id, the result of merging the two previous parameters and encoding the result using CRC32.

Since the container.build_time value will change every time you compile the application, the build will not be strictly reproducible. If you care about this, the solution is to use another configuration parameter called kernel.container_build_time and set it to a non-changing build time to achieve a strict reproducible build:

1
2
3
4
# app/config/services.yml
parameters:
    # ...
    kernel.container_build_time: '1234567890'
1
2
3
4
5
6
7
8
9
10
11
<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

    <parameters>
        <!-- ... -->
        <parameter key="kernel.container_build_time">1234567890</parameter>
    </parameters>
</container>
1
2
3
4
// app/config/services.php

// ...
$container->setParameter('kernel.container_build_time', '1234567890');
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    Symfony Code Performance Profiling

    Symfony Code Performance Profiling

    Become certified from home

    Become certified from home

    Version:

    Table of Contents

    • Configuration
      • Charset
      • Kernel Name
      • Root Directory
      • Project Directory
      • Cache Directory
      • Log Directory
      • Container Build Time

    Symfony footer

    Avatar of Robin Lehrmann, a Symfony contributor

    Thanks Robin Lehrmann for being a Symfony contributor

    2 commits • 103 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?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • 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

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony