Command line

Command line

You love command line. Maybe not... yet!

Symfony

Symfony heavily relies on command line for maintenance and development operations.

Use it for tasks like:

  • Dependencies management using #32 Composer
  • Clear the cache: php bin/console cache:clear --env=dev or php bin/console cache:clear --env=prod
  • Install assets from 3rd party bundles: php bin/console assets:install --symlink
  • Update or install database structure: php bin/console doctrine:schema:update --force
  • Send pooled email during cron process: php bin/console swiftmailer:spool:send
  • Check security warnings on all installed dependencies: php bin/console security:check
  • Generate things: php bin/console generate:controller (and much more: generate a bundle, an entity, a form,...)

Get the full list of available commands for your project using: php bin/console list.

On projects not using Symfony 3 directory structure you will have to replace bin/console with app/console.

Drupal

Drupal does not really relies on it but you can avoid an incredible amount of clicks but leveraging the power of the command line.

This was addressed in a previous issue : Use Drush !

Tips & tricks

Use shortcuts

The symfony console will try to guess which command matches best your input. Use it at your advantage.

  • c:c -> cache:clear
  • d:s:u -> doctrine:schema:update
  • a:i -> assets:install
  • a:d -> assetic:dump
  • s:s:s -> swiftmailer:spool:send

Use aliases

Define aliases to shorten your commands even more.

Add the following into your .bash_aliases file (or other supported location depending on your system):

alias dev='php bin/console --env=dev'
alias prod='php bin/console --env=prod'

With those aliases you can execute commands to a dedicated environment like this:

$ composer install
$ dev d:s:u --force
$ dev c:c
$ prod c:c
$ dev a:i --symlink

Chain commands

Chain commands using ; as separator so that you don't have to wait for the first one to finish to be able to type in the following one.

$ composer install; dev d:s:u --force; dev c:c; prod c:c; dev a:i --symlink

This command will install all dependencies, update your database structure, clear the cache for both dev and prod, install assets from 3rd party bundles as symlink. Isn't that nice ?

Example

You can easily shorten this example...

$ php bin/console --env=dev cache:clear
wait...
$ php bin/console --env=prod assetic:dump
wait...
$ php bin/console --env=prod cache:clear
wait...
$ php bin/console --env=prod doctrine:schema:update --force
wait...

...to the following one-liner:

$ dev c:c; prod a:d; dev c:c; prod d:s:u --force