Skip to content

Configuring in the Kernel

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

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

Configuring in the Kernel

Symfony applications define a kernel class (which is located by default at src/Kernel.php) that includes several configurable options. This article explains how to configure those options and shows the list of container parameters created by Symfony based on that configuration.

kernel.build_dir

type: string default: $this->getCacheDir()

This parameter stores the absolute path of a build directory of your Symfony application. This directory can be used to separate read-only cache (i.e. the compiled container) from read-write cache (i.e. cache pools). Specify a non-default value when the application is deployed in a read-only filesystem like a Docker container or AWS Lambda.

This value is also exposed via the getBuildDir() method of the kernel class, which you can override to return a different value.

kernel.bundles

type: array default: []

This parameter stores the list of bundles registered in the application and the FQCN of their main bundle class:

1
2
3
4
5
[
    'FrameworkBundle' => 'Symfony\Bundle\FrameworkBundle\FrameworkBundle',
    'TwigBundle' => 'Symfony\Bundle\TwigBundle\TwigBundle',
    // ...
]

This value is also exposed via the getBundles() method of the kernel class.

kernel.bundles_metadata

type: array default: []

This parameter stores the list of bundles registered in the application and some metadata about them:

1
2
3
4
5
6
7
8
9
10
11
[
    'FrameworkBundle' => [
        'path' => '/<path-to-your-project>/vendor/symfony/framework-bundle',
        'namespace' => 'Symfony\Bundle\FrameworkBundle',
    ],
    'TwigBundle' => [
        'path' => '/<path-to-your-project>/vendor/symfony/twig-bundle',
        'namespace' => 'Symfony\Bundle\TwigBundle',
    ],
    // ...
]

This value is not exposed via any method of the kernel class, so you can only obtain it via the container parameter.

kernel.cache_dir

type: string default: $this->getProjectDir()/var/cache/$this->environment

This parameter stores the absolute path of the cache directory of your Symfony application. The default value is generated by Symfony based on the current configuration environment. Your application can write data to this path at runtime.

This value is also exposed via the getCacheDir() method of the kernel class, which you can override to return a different value.

kernel.charset

type: string default: UTF-8

This parameter stores the type of charset or character encoding that is used in the application. This value is also exposed via the getCharset() method of the kernel class, which you can override to return a different value:

1
2
3
4
5
6
7
8
9
10
11
12
13
// src/Kernel.php
namespace App;

use Symfony\Component\HttpKernel\Kernel as BaseKernel;
// ...

class Kernel extends BaseKernel
{
    public function getCharset(): string
    {
        return 'ISO-8859-1';
    }
}

kernel.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 container 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 container 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
# config/services.yaml
parameters:
    # ...
    kernel.container_build_time: '1234567890'

kernel.container_class

type: string default: (see explanation below)

This parameter stores a unique identifier for the container class. In practice, this is only important to ensure that each kernel has a unique identifier when using applications with multiple kernels.

The default value is generated by Symfony based on the current configuration environment and the debug mode. For example, if your application kernel is defined in the App namespace, runs in the dev environment and the debug mode is enabled, the value of this parameter is App_KernelDevDebugContainer.

This value is also exposed via the getContainerClass() method of the kernel class, which you can override to return a different value:

1
2
3
4
5
6
7
8
9
10
11
12
13
// src/Kernel.php
namespace App;

use Symfony\Component\HttpKernel\Kernel as BaseKernel;
// ...

class Kernel extends BaseKernel
{
    public function getContainerClass(): string
    {
        return sprintf('AcmeKernel%s', random_int(10_000, 99_999));
    }
}

kernel.debug

type: boolean default: (the value is passed as an argument when booting the kernel)

This parameter stores the value of the current debug mode used by the application.

kernel.environment

type: string default: (the value is passed as an argument when booting the kernel)

This parameter stores the name of the current configuration environment used by the application.

This value defines the configuration options used to run the application, whereas the kernel.runtime_environment option defines the place where the application is deployed. This allows for example to run an application with the prod config (kernel.environment) in different scenarios like staging or production (kernel.runtime_environment).

kernel.logs_dir

type: string default: $this->getProjectDir()/var/log

This parameter stores the absolute path of the log directory of your Symfony application. It's calculated automatically based on the current configuration environment.

This value is also exposed via the getLogDir() method of the kernel class, which you can override to return a different value.

kernel.project_dir

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

This parameter stores the absolute path of the root directory of your Symfony application, which is used by applications to perform operations with file paths relative to the project's root directory.

By default, its value is calculated automatically as the directory where the main composer.json file is stored. This value is also exposed via the getProjectDir() method of the kernel class.

If you don't use Composer, or have moved the composer.json file location or have deleted it entirely (for example in the production servers), override the getProjectDir() method to return a different value:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// src/Kernel.php
namespace App;

use Symfony\Component\HttpKernel\Kernel as BaseKernel;
// ...

class Kernel extends BaseKernel
{
    // ...

    public function getProjectDir(): string
    {
        return \dirname(__DIR__);
    }
}

kernel.runtime_environment

type: string default: %env(default:kernel.environment:APP_RUNTIME_ENV)%

This parameter stores the name of the current runtime environment used by the application.

This value defines the place where the application is deployed, whereas the kernel.environment option defines the configuration options used to run the application. This allows for example to run an application with the prod config (kernel.environment) in different scenarios like staging or production (kernel.runtime_environment).

kernel.secret

type: string default: %env(APP_SECRET)%

This parameter stores the value of the framework.secret parameter.

kernel.trusted_hosts

This parameter stores the value of the framework.trusted_hosts parameter.

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