Back to symfony.com

Lesson 5 of 11 · 3 min

Click any paragraph or press to highlight its code

Flex recipes

Your new Symfony project is tiny on purpose: no mailer, no ORM, no templates until you decide you need them. When you do, install the feature with Composer.

Here is the magic: Symfony Flex, a Composer plugin, applies the package's recipe automatically. It creates the configuration files, registers the bundle and adds the environment variables the package needs. Zero manual setup.

Secrets and machine-specific values live in environment variables, following the twelve-factor app philosophy. The recipe already added a sensible default to your .env file. And don't worry: this file only stores harmless development defaults. In production, you define real environment variables or use Symfony's encrypted secrets vault.

This works for hundreds of packages: try composer require orm, composer require security or composer require debug. Un-installing is just as clean: composer remove mailer reverts all the changes made by the recipe.

$ composer require symfony/mailerSymfony operations: 1 recipe (executing)  - Configuring symfony/mailer (>=7.3): From github.com/symfony/recipes    Created "config/packages/mailer.yaml"    Added environment variable defaults "MAILER_DSN"    Registered the bundle in "config/bundles.php"
APP_ENV=devAPP_SECRET=ThisIsNotASecret###> symfony/mailer ###MAILER_DSN=smtp://localhost###< symfony/mailer ###