symfony/flex
Symfony Flex is a Composer plugin that streamlines installing and configuring Symfony packages. It uses recipes to auto-enable bundles, add config, env vars, and scripts, and keeps projects consistent across environments with minimal manual setup.
Installation:
Symfony Flex is automatically included when you create a new Symfony project via composer create-project symfony/skeleton. For existing projects, add it as a Composer plugin:
composer require symfony/flex --dev
No additional configuration is needed—Flex activates automatically.
First Use Case: Install a Symfony bundle/Pack and let Flex handle the boilerplate:
composer require symfony/orm-pack
This auto-generates:
config/packages/doctrine.yaml.env variables (e.g., DATABASE_URL)src/Migrationsmake:migration).Where to Look First:
symfony/orm-pack, api-platform/core).composer recipes:list to see installed recipes and composer recipes:update to sync configs.composer why-not symfony/flex to check for conflicts or composer why symfony/flex to verify installation.Bundle/Pack Installation:
composer require vendor/package-name
extra.symfony.recipe metadata and runs its recipe (e.g., copying config files, updating .env).symfony/mercure-bundle auto-configures WebSocket endpoints in config/packages/mercure.yaml.Recipe Updates:
composer recipes:update
--yes to skip confirmation prompts:
composer recipes:update --yes
Custom Recipes:
config/recipes/ (for project-specific configs) or publish them to a private Git repo.composer.json:
"extra": {
"symfony": {
"recipes": [
"path/to/local-recipe"
]
}
}
Environment-Specific Configs:
composer config extra.symfony.env to target specific environments (e.g., dev, prod).config/packages/security.yaml for staging:
composer config extra.symfony.env staging
Integration with Laravel:
symfony/mailer) in Laravel:
composer require symfony/mailer
Flex generates .env vars like MAILER_DSN.config/ and routes/ separate.composer-scripts configurator to add project-specific scripts:
"scripts": {
"post-install-cmd": [
"@symfony-scripts",
"php bin/console cache:clear"
]
}
config/ and .env volumes to persist auto-generated files.composer recipes:update in CI to ensure all environments use the same configs:
# .github/workflows/deploy.yml
- run: composer recipes:update --yes
File Overwrites:
.env, config/packages/*.yaml). Backup critical files before running recipes:update.composer recipes:update --dry-run to preview changes or exclude files via .symfony.lock:
# .symfony.lock
ignored_files:
- config/packages/custom.yaml
Recipe Conflicts:
.env var) may cause errors.composer why vendor/package to debug dependencies or manually resolve conflicts in config/packages/.Symfony-Specific Assumptions:
config/, public/, var/). Laravel projects may need to:
config/app.php).security.yaml in config/packages/security.yaml and load it in Laravel’s config/app.php).Composer Version Quirks:
composer self-update
Private Recipes:
composer config github-oauth.github.com GH_TOKEN
-vvv to see Flex’s actions:
composer recipes:update -vvv
.symfony.lock to understand applied recipes and ignored files.composer create-project symfony/skeleton test-flex
cd test-flex
composer require vendor/package
Custom Recipes:
# config/recipes/my-hybrid-recipe.yaml
name: My Hybrid Recipe
config:
packages:
- { path: config/packages/my_service.yaml }
env:
MY_VAR: "value"
composer.json:
"extra": {
"symfony": {
"recipes": ["config/recipes/my-hybrid-recipe.yaml"]
}
}
Overriding Defaults:
config/packages/ with the same name (Flex merges configs).mercure.yaml:
# config/packages/mercure.yaml
mercure:
hubs:
default:
url: "%env(MERCURE_HUB_URL)%"
public_url: "https://example.com/.well-known/mercure"
Composer Scripts:
composer.json:
"scripts": {
"post-recipes-update": [
"@symfony-scripts",
"php artisan config:clear"
]
}
config/app.php)..env vars (e.g., DATABASE_URL) while keeping Laravel’s vars (e.g., APP_ENV) separate.Console component, Flex may generate bin/console—ensure it’s not conflicting with Laravel’s artisan. Rename or alias if needed:
alias artisan='php artisan'
How can I help you explore Laravel packages today?