WARNING: You are browsing the documentation for Symfony 3.2 which is not maintained anymore. Consider upgrading your projects to Symfony 5.1.

The Console Component

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.


You can install the component in 2 different ways:

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:

#!/usr/bin/env php
// application.php

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

use Symfony\Component\Console\Application;

$application = new Application();

// ... register commands


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

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

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

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.