LinuxCommandLibrary

drush

Manage Drupal websites from the command line

TLDR

Enable module "foo"

$ drush en [foo]
copy

Uninstall module "foo"
$ drush pmu [foo]
copy

Clear all caches
$ drush cr
copy

Clear CSS and JavaScript caches
$ drush cc css-js
copy

SYNOPSIS

drush [options] <command> [arguments]
Example: drush status
Example: drush pm:enable my_module --yes
Example: drush updatedb

PARAMETERS

--root=<path>
    Specifies the absolute path to the Drupal installation directory.

--uri=<uri>
    Specifies the URI of the Drupal site to operate on, crucial for multi-site setups.

--yes (-y)
    Automatically confirms any prompt, useful for scripting non-interactive operations.

--no (-n)
    Automatically declines any prompt, useful for preventing accidental changes.

--verbose (-v)
    Increases the verbosity of Drush output, providing more detailed information.

--alias=<alias_name>
    Executes the command on a site defined by a Drush alias, enabling remote or multi-site management.

--user=<id_or_name>
    Runs the command as a specific user ID or name, useful for permissions-related tasks.

DESCRIPTION

Drush (Drupal Shell) is a command-line interface (CLI) for Drupal. It provides a powerful set of commands that allow developers and site administrators to interact with their Drupal sites from the terminal, automating many common tasks. Drush streamlines operations such as installing Drupal, managing modules and themes, running database updates, clearing caches, generating content, and executing site migrations. By eliminating the need to navigate the administrative interface for routine tasks, Drush significantly improves productivity and efficiency, making it an indispensable tool for Drupal development and maintenance workflows. It integrates deeply with Drupal's APIs, providing robust and reliable functionality.

CAVEATS

Context Dependency: Drush commands often rely on being executed within a Drupal site's root directory or explicitly specifying it with --root.
Version Compatibility: Ensure your Drush version is compatible with your Drupal version. Incompatibility can lead to errors or unexpected behavior.
Environment Differences: Behavior might vary slightly between different server environments (e.g., local, staging, production) due to PHP configurations, pathing, or user permissions.
Database Backups: Always back up your database before running significant Drush commands like updatedb or config:import, as they can alter data irreversibly.

SITE ALIASES

Drush aliases (typically defined in ~/.drush/sites/ or within Drupal projects) allow defining connection details for local, remote, or multiple Drupal sites, simplifying command execution across different environments without needing to specify --root or --uri each time.

EXTENSION SYSTEM

Drush is highly extensible; custom Drush commands can be created within Drupal modules or standalone projects to automate specific site-specific functionalities, integrating deeply with Drupal's API and extending Drush's capabilities.

HISTORY

Drush was created by Arto Bendiken in 2007. It quickly became an essential tool for Drupal developers due to its ability to streamline common tasks. Over the years, it has evolved significantly, adopting a command-line application structure based on Symfony Console in Drush 8, and later moving to Composer-based distribution. Drush 9 and subsequent versions (currently Drush 12) require Composer for installation and have refined its command structure, aligning more closely with modern PHP development practices. Its continuous development reflects the changing landscape of Drupal and its ecosystem.

SEE ALSO

php(1), composer(1), mysql(1), git(1), rsync(1), ssh(1)

Copied to clipboard