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.

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.

General

php bin/console list — List all available commands.

php bin/console list

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

php bin/console help make:entity

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

php bin/console about

symfony serve — Start the Symfony local web server.

symfony serve -d

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

symfony new my-project --webapp

Code Generation (make:)

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

php bin/console make:entity Product

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

php bin/console make:controller ProductController

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

php bin/console make:form ProductType

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

php bin/console make:migration

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

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

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

php bin/console make:subscriber ExceptionSubscriber

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

php bin/console make:twig-extension AppExtension

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

php bin/console make:voter ProductVoter

Database & Doctrine

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

php bin/console doctrine:database:create

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

php bin/console doctrine:migrations:migrate

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

php bin/console doctrine:migrations:status

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

php bin/console doctrine:schema:validate

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

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

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

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

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

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

Cache & Config

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

php bin/console cache:clear

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

php bin/console cache:warmup

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

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

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

php bin/console debug:config framework

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

php bin/console config:dump-reference security

Debug & Routes

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

php bin/console debug:router

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

php bin/console debug:router app_product_show

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

php bin/console router:match /product/42

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

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

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

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

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

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

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

php bin/console debug:twig

Messenger & Security

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

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

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

php bin/console messenger:failed:show

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

php bin/console messenger:failed:retry

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

php bin/console security:hash-password

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

php bin/console secrets:set DATABASE_PASSWORD

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

  • artisan – command-line tool of the Laravel framework
  • cargo – package and build manager for Rust
  • composer – dependency manager for PHP