drupal
Manage Drupal websites from the command line
TLDR
Install a module
Uninstall a module
Clear all caches
View current Drupal installation status
SYNOPSIS
drush [options] [command] [arguments]
PARAMETERS
--root=path or -r path
Specifies the Drupal root directory to operate on.
--uri=uri or -l uri
Specifies the URI of the Drupal site when working with multisite installations (e.g., `http://example.com`).
--alias=alias or -A alias
Specifies a site alias defined in Drush configuration files.
--yes or -y
Assumes 'yes' to all prompts, useful for automation.
--no or -n
Assumes 'no' to all prompts.
--quiet or -q
Suppresses non-error messages.
--simulate or -s
Simulates running the command without making changes.
--include=path
Include a directory of Drush commands.
--strict=0
Turns off strict mode for command validation.
DESCRIPTION
The Linux command "drupal" does not exist as a standalone utility. Drupal itself is an open-source content management system (CMS) used for building websites and applications, running on a web server (like Apache or Nginx), PHP, and a database (like MySQL or PostgreSQL). Command-line interactions with a Drupal site are typically handled by specialized tools such as Drush (Drupal Shell) or Drupal Console. This analysis focuses on Drush, which is the most widely adopted and established command-line interface for Drupal.
Drush provides a powerful set of commands to automate common administrative tasks, development operations, and site maintenance. It allows developers and administrators to perform actions like clearing caches, managing users, updating modules, installing Drupal, running database updates, and executing custom PHP code directly from the terminal, significantly streamlining workflows and facilitating scripting.
CAVEATS
The primary caveat is that a direct "drupal" command does not exist in standard Linux distributions. Users often mistakenly search for it when trying to interact with Drupal from the command line. Instead, you must install a separate tool like Drush or Drupal Console. These tools themselves have dependencies, primarily PHP and Composer, and must be correctly configured to locate your Drupal installation. Running `drush` commands requires appropriate file system permissions for the user executing the command.
COMMON DRUSH USE CASES
Drush is indispensable for automating routine tasks. Key uses include:
- Cache Management: `drush cr` (cache rebuild) is a frequently used command after configuration changes or code deployments.
- Module/Theme Management: `drush en module_name` (enable), `drush dis module_name` (disable), `drush pm:uninstall module_name` (uninstall).
- Database Updates: `drush updb` runs all pending database updates after code changes or module updates.
- Configuration Management: `drush config:export` (cex) and `drush config:import` (cim) manage Drupal 8/9/10 configuration.
- User Management: `drush user:create`, `drush user:block`, `drush user:unblock`, `drush user:login` (generates a one-time login link).
- Site Installation: `drush site:install` can automate the entire Drupal installation process.
INSTALLATION
The recommended way to install Drush for modern Drupal versions (8, 9, 10) is via Composer, as a dependency within your Drupal project. This ensures that the correct Drush version compatible with your Drupal version is used.composer require drush/drush
After installation, you can run Drush commands from your Drupal root directory (where `composer.json` and `web` or `docroot` are located) using `vendor/bin/drush` or by adding `vendor/bin` to your system's PATH.
HISTORY
Drush (Drupal Shell) was first released in 2007 by Antoine Beaupré. It quickly gained popularity as the essential command-line utility for Drupal development and administration, becoming a de-facto standard in the Drupal ecosystem. Its development has been community-driven, adapting to various Drupal versions (Drupal 6, 7, 8, 9, and 10). With the advent of Composer for managing PHP dependencies in Drupal 8+, Drush transitioned to being primarily installed via Composer within individual Drupal projects, ensuring version compatibility and simplifying project setup. While Drupal Console emerged as an alternative with Symfony Console integration, Drush remains the most widely used and mature CLI tool for Drupal.