CLI and deployment
bin/magento is built on Symfony Console, so commands in bin/console look almost the same. Below are the matching commands and a typical prod deploy.
| bin/magento | bin/console | Note |
|---|---|---|
| cache:flush, cache:clean | cache:clear; cache:pool:clear cache.app | The system cache and data are different things. |
| setup:upgrade | doctrine:migrations:migrate | Only schema and data from migrations. |
| setup:db-declaration:generate-whitelist | make:migration, doctrine:migrations:diff | Generates a migration class. |
| setup:di:compile | cache:warmup | In prod it runs as part of cache:clear. |
| deploy:mode:set production | APP_ENV=prod, APP_DEBUG=0 | Plus composer dump-env prod. |
| module:enable / module:status | config/bundles.php; about | about shows the version, environment and paths. |
| dev:di:info | debug:container, debug:autowiring | Plus lint:container. |
| config:show | debug:config, config:dump-reference | Actual values and all available options. |
| — | debug:router, router:match | Routes. |
| — | debug:event-dispatcher | Listeners with priorities. |
| queue:consumers:start | messenger:consume async | After deployment: messenger:stop-workers. |
| cron:run | messenger:consume scheduler_default | Or the system cron. |
| indexer:reindex | your own command | There are no indexers. |
| admin:user:create | your own command, fixtures | Users are your own entity. |
| — | make:controller, make:entity, make:crud, make:command | MakerBundle generates boilerplate. |
| — | lint:yaml, lint:container, doctrine:schema:validate | Worth running in CI. |
Magento · command
class ImportCommand extends Command
{
protected function configure(): void
{
$this->setName('vendor:faq:import');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
return Command::SUCCESS;
}
}
// + registration in di.xml in CommandList
Symfony · command (the same Console component)
#[AsCommand(name: 'app:faq:import', description: 'Import FAQ from CSV')]
final class ImportCommand extends Command
{
public function __construct(private Importer $importer)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->success('Imported');
return Command::SUCCESS;
}
}
// no registration needed: autoconfigure
Deploying to prod
Symfony · typical sequence
composer install --no-dev --optimize-autoloader
composer dump-env prod
APP_ENV=prod bin/console cache:clear # also warms up the cache
bin/console doctrine:migrations:migrate --no-interaction
bin/console messenger:stop-workers # supervisor restarts the workers with the new code