Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Components
  4. The Console Component
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • Installation
  • Creating a Console Application
  • Learn more

The Console Component

Edit this page

Warning: You are browsing the documentation for Symfony 3.0, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

The Console Component

The Console component eases the creation of beautiful and testable command line interfaces.

The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.

Installation

You can install the component in 2 different ways:

  • Install it via Composer (symfony/console on Packagist);
  • Use the official Git repository (https://github.com/symfony/console).

Then, require the vendor/autoload.php file to enable the autoloading mechanism provided by Composer. Otherwise, your application won't be able to find the classes of this Symfony component.

Creating a Console Application

First, you need to create a PHP script to define the console application:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env php
<?php
// application.php

require __DIR__.'/vendor/autoload.php';

use Symfony\Component\Console\Application;

$application = new Application();

// ... register commands

$application->run();

Then, you can register the commands using add():

1
2
// ...
$application->add(new GenerateAdminCommand());

See the Console Commands article for information about how to create commands.

Learn more

  • Console Commands
  • Changing the Default Command
  • Understanding how Console Arguments Are Handled
  • Using Events
  • Debug Formatter Helper
  • Dialog Helper
  • Formatter Helper
  • The Console Helpers
  • Process Helper
  • Progress Bar
  • Progress Helper
  • Question Helper
  • Table
  • Table Helper
  • Using the Logger
  • Building a single Command Application
  • Using Console Commands, Shortcuts and Built-in Commands
  • The Console Helpers
  • How to Call Other Commands
  • How to Color and Style the Console Output
  • How to Call a Command from a Controller
  • How to Define Commands as Services
  • Console Input (Arguments & Options)
  • How to Enable Logging in Console Commands
  • How to Generate URLs from the Console
  • How to Style a Console Command
  • How to Use the Console
  • Verbosity Levels
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Online Sylius certification, take it now!

Online Sylius certification, take it now!

Check Code Performance in Dev, Test, Staging & Production

Check Code Performance in Dev, Test, Staging & Production

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Alexey Bakulin, a Symfony contributor

Thanks Alexey Bakulin (@bakulinav) for being a Symfony contributor

1 commit • 2 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia