# Symfony — CLI und bin/console für Symfony-Projekte

> Praxis-Guide zu Symfony: CLI für lokalen Server und bin/console für make, Doctrine, Cache, Routing und Debugging deiner Symfony-Anwendungen.

Source: https://www.jpkc.com/db/cheatsheets/build-languages/symfony/

<!-- PROSE:intro -->
Symfony ist eines der führenden PHP-Frameworks für Webanwendungen und APIs. Im Alltag arbeitest du mit zwei Werkzeugen: Die separate `symfony`-CLI (das Symfony-Binary) startet den lokalen Entwicklungsserver, legt neue Projekte an und bündelt Tooling rund um Symfony Cloud. Für alles innerhalb deiner Anwendung – Code-Generierung, Datenbank-Migrationen, Cache, Routing und Debugging – nutzt du `php bin/console`, die Console-Komponente des Frameworks. Dieser Guide bündelt die Kommandos, die du im Projektalltag am häufigsten brauchst.
<!-- PROSE:intro:end -->

## Allgemein

`php bin/console list` — Listet alle verfügbaren Kommandos auf.

```bash
php bin/console list
```

`php bin/console help <command>` — Zeigt die Hilfe zu einem bestimmten Kommando.

```bash
php bin/console help make:entity
```

`php bin/console about` — Zeigt Informationen über das aktuelle Projekt.

```bash
php bin/console about
```

`symfony serve` — Startet den lokalen Symfony-Webserver.

```bash
symfony serve -d
```

`symfony new <name>` — Legt ein neues Symfony-Projekt an.

```bash
symfony new my-project --webapp
```

## Code-Generierung (make:)

`php bin/console make:entity` — Erzeugt oder aktualisiert eine Doctrine-Entity-Klasse.

```bash
php bin/console make:entity Product
```

`php bin/console make:controller` — Erzeugt eine neue Controller-Klasse.

```bash
php bin/console make:controller ProductController
```

`php bin/console make:form` — Erzeugt eine neue Form-Type-Klasse.

```bash
php bin/console make:form ProductType
```

`php bin/console make:migration` — Erzeugt eine Migration auf Basis der Entity-Änderungen.

```bash
php bin/console make:migration
```

`php bin/console make:command` — Erzeugt eine neue Console-Command-Klasse.

```bash
php bin/console make:command app:send-emails
```

`php bin/console make:subscriber` — Erzeugt einen neuen Event-Subscriber.

```bash
php bin/console make:subscriber ExceptionSubscriber
```

`php bin/console make:twig-extension` — Erzeugt eine Twig-Extension.

```bash
php bin/console make:twig-extension AppExtension
```

`php bin/console make:voter` — Erzeugt einen neuen Security-Voter.

```bash
php bin/console make:voter ProductVoter
```

## Datenbank & Doctrine

`php bin/console doctrine:database:create` — Legt die konfigurierte Datenbank an.

```bash
php bin/console doctrine:database:create
```

`php bin/console doctrine:migrations:migrate` — Führt ausstehende Datenbank-Migrationen aus.

```bash
php bin/console doctrine:migrations:migrate
```

`php bin/console doctrine:migrations:status` — Zeigt den Status der Migrationen.

```bash
php bin/console doctrine:migrations:status
```

`php bin/console doctrine:schema:validate` — Prüft die Mapping-Dateien und das Datenbankschema.

```bash
php bin/console doctrine:schema:validate
```

`php bin/console doctrine:schema:update --dump-sql` — Zeigt das SQL, das zum Aktualisieren des Datenbankschemas nötig ist.

```bash
php bin/console doctrine:schema:update --dump-sql
```

`php bin/console doctrine:fixtures:load` — Lädt Daten-Fixtures in die Datenbank.

```bash
php bin/console doctrine:fixtures:load --append
```

`php bin/console dbal:run-sql '<sql>'` — Führt rohes SQL direkt aus.

```bash
php bin/console dbal:run-sql 'SELECT count(*) FROM product'
```

## Cache & Konfiguration

`php bin/console cache:clear` — Leert den Anwendungs-Cache.

```bash
php bin/console cache:clear
```

`php bin/console cache:warmup` — Wärmt den Cache vor.

```bash
php bin/console cache:warmup
```

`php bin/console cache:pool:clear <pool>` — Leert einen bestimmten Cache-Pool.

```bash
php bin/console cache:pool:clear cache.app
```

`php bin/console debug:config <bundle>` — Zeigt die aufgelöste Konfiguration eines Bundles.

```bash
php bin/console debug:config framework
```

`php bin/console config:dump-reference <bundle>` — Zeigt die vollständige Standard-Konfigurationsreferenz.

```bash
php bin/console config:dump-reference security
```

## Debugging & Routen

`php bin/console debug:router` — Listet alle registrierten Routen auf.

```bash
php bin/console debug:router
```

`php bin/console debug:router <name>` — Zeigt Details zu einer bestimmten Route.

```bash
php bin/console debug:router app_product_show
```

`php bin/console router:match <path>` — Zeigt, welche Route zu einem URL-Pfad passt.

```bash
php bin/console router:match /product/42
```

`php bin/console debug:container` — Listet alle Services im Container auf.

```bash
php bin/console debug:container --show-arguments
```

`php bin/console debug:container <service>` — Zeigt Details zu einem bestimmten Service.

```bash
php bin/console debug:container App\Service\Mailer
```

`php bin/console debug:event-dispatcher` — Listet alle registrierten Event-Listener auf.

```bash
php bin/console debug:event-dispatcher kernel.request
```

`php bin/console debug:twig` — Zeigt Twig-Funktionen, -Filter und -Globals.

```bash
php bin/console debug:twig
```

## Messenger & Security

`php bin/console messenger:consume <transport>` — Konsumiert Nachrichten aus einem Transport (Queue-Worker).

```bash
php bin/console messenger:consume async --limit=10
```

`php bin/console messenger:failed:show` — Zeigt fehlgeschlagene Nachrichten.

```bash
php bin/console messenger:failed:show
```

`php bin/console messenger:failed:retry` — Verarbeitet fehlgeschlagene Nachrichten erneut.

```bash
php bin/console messenger:failed:retry
```

`php bin/console security:hash-password` — Hasht ein Klartext-Passwort.

```bash
php bin/console security:hash-password
```

`php bin/console secrets:set <name>` — Setzt ein Secret im Vault.

```bash
php bin/console secrets:set DATABASE_PASSWORD
```

<!-- PROSE:outro -->
## Fazit

Mit der `symfony`-CLI und `bin/console` hast du fast alles in der Hand, was ein Symfony-Projekt im Alltag braucht – vom lokalen Server über Code-Generierung bis zu Cache und Routing. Der lokale Server (`symfony serve`) ist ausschließlich für die Entwicklung gedacht; in Produktion läuft deine App hinter einem echten Webserver wie nginx oder Apache mit PHP-FPM. Vorsicht bei datenverändernden Doctrine-Kommandos: `doctrine:migrations:migrate` sowie `doctrine:database:drop` und `doctrine:schema:drop` können Daten unwiderruflich löschen – lege vorher ein Backup an und setze in Produktion `--no-interaction` nur bewusst und geprüft ein. `cache:clear` ist harmlos, sollte in Produktion aber im richtigen Environment laufen. Die Console ist erweiterbar: Mit `make:command` baust du dir eigene Kommandos im selben Stil.

## Weiterführende Links

- [Symfony-Dokumentation](https://symfony.com/doc/current/index.html) – offizielle Referenz zu Framework, Console und Komponenten (englisch)
- [The Console Component](https://symfony.com/doc/current/components/console.html) – Details zu `bin/console` und eigenen Kommandos (englisch)
- [Symfony Local Web Server](https://symfony.com/doc/current/setup/symfony_server.html) – Einrichtung und Nutzung der `symfony`-CLI (englisch)
<!-- PROSE:outro:end -->

## Verwandte Kommandos

- [artisan](https://www.jpkc.com/db/cheatsheets/build-languages/artisan/) – Kommandozeilen-Tool des Laravel-Frameworks
- [cargo](https://www.jpkc.com/db/cheatsheets/build-languages/cargo/) – Paket- und Build-Manager für Rust
- [composer](https://www.jpkc.com/db/cheatsheets/build-languages/composer/) – Abhängigkeits-Manager für PHP

