# Symfony — CLI and bin/console for Symfony Projects

> Practical guide to Symfony: the CLI for the local server and bin/console for make, Doctrine, cache, routing and debugging your Symfony apps.

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

<!-- PROSE:intro -->
Symfony is one of the leading PHP frameworks for web applications and APIs. Day to day you work with two tools: the separate `symfony` CLI (the Symfony binary) starts the local development server, scaffolds new projects and bundles tooling around Symfony Cloud. For everything inside your application – code generation, database migrations, cache, routing and debugging – you use `php bin/console`, the framework's Console component. This guide collects the commands you reach for most often in everyday project work.
<!-- PROSE:intro:end -->

## General

`php bin/console list` — List all available commands.

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

`php bin/console help <command>` — Show help for a specific command.

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

`php bin/console about` — Show information about the current project.

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

`symfony serve` — Start the Symfony local web server.

```bash
symfony serve -d
```

`symfony new <name>` — Create a new Symfony project.

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

## Code Generation (make:)

`php bin/console make:entity` — Create or update a Doctrine entity class.

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

`php bin/console make:controller` — Create a new controller class.

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

`php bin/console make:form` — Create a new form type class.

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

`php bin/console make:migration` — Generate a migration based on entity changes.

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

`php bin/console make:command` — Create a new console command class.

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

`php bin/console make:subscriber` — Create a new event subscriber class.

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

`php bin/console make:twig-extension` — Create a Twig extension.

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

`php bin/console make:voter` — Create a new security voter.

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

## Database & Doctrine

`php bin/console doctrine:database:create` — Create the configured database.

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

`php bin/console doctrine:migrations:migrate` — Run pending database migrations.

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

`php bin/console doctrine:migrations:status` — Show migration status.

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

`php bin/console doctrine:schema:validate` — Validate the mapping files and database schema.

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

`php bin/console doctrine:schema:update --dump-sql` — Show SQL needed to update database schema.

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

`php bin/console doctrine:fixtures:load` — Load data fixtures into the database.

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

`php bin/console dbal:run-sql '<sql>'` — Execute raw SQL directly.

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

## Cache & Config

`php bin/console cache:clear` — Clear the application cache.

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

`php bin/console cache:warmup` — Warm up the cache.

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

`php bin/console cache:pool:clear <pool>` — Clear a specific cache pool.

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

`php bin/console debug:config <bundle>` — Show resolved configuration for a bundle.

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

`php bin/console config:dump-reference <bundle>` — Show full default configuration reference.

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

## Debug & Routes

`php bin/console debug:router` — List all registered routes.

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

`php bin/console debug:router <name>` — Show details of a specific route.

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

`php bin/console router:match <path>` — Show which route matches a given URL path.

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

`php bin/console debug:container` — List all services in the container.

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

`php bin/console debug:container <service>` — Show details of a specific service.

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

`php bin/console debug:event-dispatcher` — List all registered event listeners.

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

`php bin/console debug:twig` — Show Twig functions, filters, and globals.

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

## Messenger & Security

`php bin/console messenger:consume <transport>` — Consume messages from a transport (queue worker).

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

`php bin/console messenger:failed:show` — Show failed messages.

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

`php bin/console messenger:failed:retry` — Retry failed messages.

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

`php bin/console security:hash-password` — Hash a plain-text password.

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

`php bin/console secrets:set <name>` — Set a secret in the vault.

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

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

Between the `symfony` CLI and `bin/console` you have nearly everything a Symfony project needs day to day – from the local server to code generation, cache and routing. The local server (`symfony serve`) is meant for development only; in production your app runs behind a real web server such as nginx or Apache with PHP-FPM. Be careful with data-changing Doctrine commands: `doctrine:migrations:migrate` along with `doctrine:database:drop` and `doctrine:schema:drop` can delete data irreversibly – take a backup first and use `--no-interaction` in production only deliberately and after review. `cache:clear` is harmless, but in production it should run in the correct environment. The console is extensible: with `make:command` you build your own commands in the same style.

## Further Reading

- [Symfony Documentation](https://symfony.com/doc/current/index.html) – official reference for the framework, console and components
- [The Console Component](https://symfony.com/doc/current/components/console.html) – details on `bin/console` and custom commands
- [Symfony Local Web Server](https://symfony.com/doc/current/setup/symfony_server.html) – setup and usage of the `symfony` CLI
<!-- PROSE:outro:end -->

## Related Commands

- [artisan](https://www.jpkc.com/db/en/cheatsheets/build-languages/artisan/) – command-line tool of the Laravel framework
- [cargo](https://www.jpkc.com/db/en/cheatsheets/build-languages/cargo/) – package and build manager for Rust
- [composer](https://www.jpkc.com/db/en/cheatsheets/build-languages/composer/) – dependency manager for PHP

