Symfony 7 Cheat Sheet
A quick reference for the commands and config you reach for most. For the full reference, the official docs are at symfony.com/doc/current, and the 7.4 long-term-support branch is at symfony.com/doc/7.4. Which version to run is its own question: see Symfony 7.4 LTS or 8.1: which to use.
What this page covers
Setup and console
Creating a project, the Symfony CLI, and the console commands worth memorizing.
Structure and dependencies
Where things live in a Symfony 7 project, and managing packages with Composer and Flex.
Doctrine and the database
Entities, migrations and the commands around them.
Routing and controllers
Attribute routing, controller shape, and generating URLs.
Forms, Twig and sessions
Form types, template syntax, and flash messages.
Security, testing and profiling
Current security practice, what is new in 7.x, running tests in CI, and reading the profiler.
Tested on
Symfony 7.4.23 on PHP 8.3.36, in a project made with composer create-project "symfony/skeleton:7.4.*" plus the ORM, Twig, form, security, asset-mapper and maker packages, on 11/13/2026. Every console command below was listed by bin/console list or run in that project. Two things were not tested: the Symfony CLI (symfony new, symfony serve), which was not installed on the test machine, and anything that needs a running database.
Project setup
composer create-project "symfony/skeleton:7.4.*" my_project
cd my_project
composer require webapp
With the Symfony CLI installed, symfony new my_project --webapp does the same in one step, and symfony serve starts a local web server. Working on Symfony 2.x? The older Symfony cheat sheet covers the app/console commands.
Symfony 7 needs PHP 8.2 or later.
Console
Every command runs through bin/console:
bin/console list
bin/console cache:clear --env=prod
The second command printed Cache for the "prod" environment (debug=false) was successfully cleared.
Where things live
- Your code goes in
src/, organized by PHP namespace. Bundles are for packages you share, not for your own application code. - Environment variables go in
.env, with machine-specific values in.env.local. - Service and application config is in
config/services.yaml. - Templates are named
something.html.twig:make:controller Democreatedtemplates/demo/index.html.twig. - Symfony Flex adds the config for a package when you
composer requireit.
Doctrine and the database
bin/console make:entity
bin/console make:entity --regenerate
bin/console make:migration
bin/console doctrine:migrations:migrate
--regenerate rewrites the getters and setters of an existing entity and does not add fields; add --overwrite to replace methods that already exist.
Older guides generate entities from an existing database with doctrine:mapping:import. That command is not in a current project: the only doctrine:mapping commands listed were doctrine:mapping:describe and doctrine:mapping:info. Write the entity by hand or with make:entity, and map it with PHP attributes. The field-type table shows what each MySQL column type becomes.
Routing and controllers
bin/console debug:router
#[Route('/blog', name: 'blog_list')]
return $this->redirectToRoute('dashboard');
$routeName = $request->attributes->get('_route');
$user = $this->getUser();
$userId = $user?->getId();
make:controller Demo added a route that debug:router listed as app_demo ANY /demo.
Forms
if ($form->isSubmitted() && $form->isValid()) { /* ... */ }
$unmapped = $form->get('unmapped_field')->getData();
$entityManager->persist($entity);
$entityManager->flush();
If a form will not install, note that the form component needs symfony/property-access: the cache failed to build with a dependency on a non-existent service "property_accessor" until it was added.
Flash messages and assets
{% for message in app.flashes('notice') %}
<div class="flash-notice">{{ message }}</div>
{% endfor %}
bin/console assets:install --symlink
bin/console assets:compress <paths>
The compress command is assets:compress, which takes the files to compress as arguments; asset:precompress, a name some guides use, was not in the command list. AssetMapper (asset-map:compile) handles JavaScript and CSS without a front-end bundler.
Checking and debugging
Run on 11/17/2026 in a fresh Symfony 7.4.23 skeleton (PHP 8.3.36) with Twig, the maker bundle, the security bundle and the validator added. Each command below ran, and the line after it is what it reported.
| Command | What it showed |
|---|---|
bin/console about |
Version v7.4.23, Long-Term Support Yes, end of maintenance 11/2028, end of life 11/2029, the kernel, environment and PHP |
bin/console lint:twig templates |
All 4 Twig files contain valid syntax; a broken file is named with its line |
bin/console lint:yaml config |
All 11 YAML files contain valid syntax |
bin/console lint:container |
all services are injected with values that are compatible with their type declarations |
bin/console debug:autowiring --all request |
the types you can type-hint, such as Symfony\Component\HttpFoundation\RequestStack |
bin/console debug:config framework session |
the live session settings, such as cookie_httponly: true and cookie_samesite: lax |
bin/console config:dump-reference twig |
every option the twig key accepts, with defaults |
bin/console debug:event-dispatcher kernel.request |
the listeners on that event in order, from DebugHandlersListener (priority 2048) down |
bin/console debug:container --parameters |
every container parameter and its value |
bin/console debug:container --env-vars |
the environment variables the app reads, such as APP_SECRET |
bin/console debug:dotenv |
which of .env, .env.local, .env.dev and the others exist, in priority order |
bin/console debug:twig --filter=upper |
upper(string) |
A fresh project with no controllers listed one route from debug:router, _preview_error at /_error/{code}.{_format}, which is the error preview page and not yours.
Generators
With the maker bundle installed (composer require --dev symfony/maker-bundle), bin/console list make listed these, among others: make:command, make:controller, make:crud, make:entity, make:form, make:listener, make:migration, make:registration-form, make:security:form-login, make:test, make:twig-extension, make:user, make:validator, make:voter and make:webhook. Run one with no arguments and it asks for what it needs.
Environment values and secrets
Values in .env are committed defaults. Put machine-specific values in .env.local, which stays out of Git. To store a value that must not sit in a file as plain text, bin/console secrets:set NAME writes it to the encrypted vault; --local writes to the local vault and --random generates the value. Reading the vault back and the production key handling were not tested here.
Quick commands
| Description | Command |
|---|---|
| Clear cache | bin/console cache:clear --env=prod |
| List routes | bin/console debug:router |
| Make a migration | bin/console make:migration |
| Run migrations | bin/console doctrine:migrations:migrate |
| Start a web server | symfony serve (Symfony CLI, not tested here) |
Useful links
- Official docs: symfony.com/doc/current
- Releases: symfony.com/releases
Note: This covers Symfony 7, which is the current LTS at 7.4; Symfony 8.1 is the current stable release. For anything not here, the official Symfony documentation is the reference. To see the PHP each Symfony version needs and when its fixes end, use the Symfony and PHP version checker.
Further reading
Absorbed from a 65-word links page that existed only to hold them, and which is not worth its own URL:
- symfony.com/7 - the release hub
- Symfony 7.3, curated new features
- Symfony 7.1, curated new features
- Symfony 7 in a nutshell, with Nicolas Grekas
- The Symfony release process - which version is LTS, and until when