Introduction: The Most Popular CLI Tool for Drupal 8
[openingText]
This Tutorial will show how to manage Drupal 8 web servers, including configuration & dependency settings for required modules & programming languages, using Drush.
Drush is a command line utility for managing Drupal 8 and must be installed on the web server. Usually, this requires a VPS hosting,dedicated server hosting, or cloud hosting plan.
Some [tool]Drupal 8[/tool] specialist hosts offer Drush pre-installed on shared hosting plans. Drush is CLI administration of the Drupal CMS with a suite of professional power tools.
[/openingText]
Step One: [stepName]Install Drush on the Web Server (Linux or Windows)[/stepName]
[step]
[howToDirection]Follow this HostAdvice Tutorial in order to install Drush on CentOS using Sudo:
[/howToDirection]
The guide also includes information for installing Drush with Composer which will work on Windows servers if Curl, Git, Cygwin, & other packages are made available.
[howToDirection]In order to install the Drush 8.x version:
composerglobalrequire drush/drush:8.*
Note:Drupal 8 websites hosted on shared plans may not have permission to install Drush on platform servers. In this case, make sure the web host has installed Drush.
[/howToDirection]
[howToDirection]To get started learning about Drush, run:
$ drush help
or
$ drush topic
Scroll through the help & topic information provided in the CLI to learn more about the available Drush commands.[/howToDirection]
[/step]
Step Two: [stepName]Use Drush to Install Drupal 8 Core[/stepName]
[step]
[howToDirection]
First, run this command using Git Bash or PuTTY to install the Drupal 8 core distribution files via command line using Drush:
drush dl drupal-8 --select
[/howToDirection]
[howToDirection]The dl command will download the latest version of Drupal 8 to the root directory or sub-folder according to path. Use the following commands to install the files:
drush site-install
[/howToDirection]
Alias:
drush si
Arguments – Profile:
profile: The install profile you wish to run. Defaultsto'default'in D6, 'standard'in D7+, unless an install profile is marked as exclusive (oras a distribution in D8+ terminology) in which case that is used.
Arguments – Key Value:
key=value...: Any additional settings you wish to pass to the profile. Fully supported on D7+, partially supported on D6 (single step configure forms only). The key is in the form [form name].[parameter name] on D7 or just [parameter name] on D6.
Options: There are 13 available Drush options for the “site install” command:
--db-url
--db-url :db-url
--db-prefix : An optional table prefix to use for initial install. Can be a key-value array of tables/prefixes in a drushrc file (not the command line).
--db-su
--db-su : db-su
--db-su-pw
--db-su-pw : db-su-pw
--account-name : uid1 name. Defaults to admin
--account-pass : uid1 pass. Defaults to a randomly generated password. If desired, set a fixed password in drushrc.php.
--account-mail : uid1 email. Defaults to admin@example.com
--locale
--locale : locale
--clean-url : Defaults to clean; use --no-clean-url to disable. Note that Drupal 8 and later requires clean.
--site-name : Defaults to Site-Install
--site-mail : From: for system mailings. Defaults to admin@example.com
--sites-subdir
--sites-subdir : sites-subdir
--config-dir : A path pointing to a full set of configuration which should be imported after installation.
Using these Drush commands, it is possible to create the MySQL database & Drupal 8 installation with fine grained details over configuration settings which can be automated.
[/step]
Step Three: [stepName]Use Drush to Install Drupal 8 Modules[/stepName]
[step]
Drush is preferred by professional Drupal 8 administrators, programmers, & developers because it can speed up common repetitive tasks related to maintenance or installation.
[howToDirection]
To download a Drupal 8 module by Drush command:
drush dl module_name
[/howToDirection]
[howToDirection]
To install a Drupal 8 module using Drush, use the CLI to run:
drush en module_name
[/howToDirection]
Note that the Drupal Console module & Composer offer alternative means to install Drupal 8 modules using the command line, but Drush is the most technical option.
[/step]
Step Four: [stepName]Use Drush to Install Drupal 8 Themes[/stepName]
[step]
The commands for installing a Drupal 8 theme are the same as for modules, with a few additional options for Theme Configuration provided by the Drush command values.
[howToDirection]
Download a Drupal 8 theme:
$ drush dl themename
[/howToDirection]
[howToDirection]
Enable the theme:
$ drush en themename
[/howToDirection]
[howToDirection]
List of all installed themes:
$ drush pm-list --type=theme
[/howToDirection]
[howToDirection]
Set the theme to be default:
$ drush config-set system.theme default themename
[/howToDirection]
[howToDirection]
Set the theme to be administration section use:
$ drush config-set system.theme admin themename
[/howToDirection]
[howToDirection]
Other useful Drush commands are for clearing the theme cache:
$ drush cr
[/howToDirection]
This command will actually rebuild the Drupal 8 cache on the web server. Use Drush commands for Theme Development or to speed up the construction of new websites.
[/step]
Step Five: [stepName]Use Drush to Update Drupal 8 Projects[/stepName]
[step]
Another major use of Drush is in automating regular Drupal maintenance tasks like security updates, module upgrades, patches, & code versions with the command line.
[howToDirection]
To list all available project updates (requires Composer):
composer outdated 'drupal/*'
[/howToDirection]
[howToDirection]
List all security updates:
drushpm:security
[/howToDirection]
[howToDirection]
Install all module/theme updates (requires Composer):
composer update drupal/modulename --with-dependencies
[/howToDirection]
[howToDirection]
Run any database updates:
drush updatedb
[/howToDirection]
[howToDirection]
Rebuild the site cache:
drush cr
[/howToDirection]
[howToDirection]
Update the installed Drupal 8 version:
drush up drupal
Update a single module only:
drush up module_name
Update only security patches:
drush up --security-only
Run pending updates on a staging site:
$ drush @staging updatedb
Synchronize staging files to production:
$ drush rsync @staging:%files/@live:%files
Synchronize database from production to dev, excluding the cache table:
$ drush sql-sync --structure-tables-key=custom @live@dev
[/howToDirection]
These commands show only the minimum of what Drush can do if properly deployed for Drupal 8 website management. See these resources for more information:
Drush is one of the most active & widely supported modules in the Drupal community.
[/step]
Conclusion: Drush & Composer for Web Server Management
Drush & Composer are increasingly viewed as mandatory web server extensions for managing Drupal 8 with command line tools to speed up repetitive maintenance tasks.
Linux & Windows systems administrators familiar with CLI Tools can use Drush effectively for installing websites, updating modules, managing themes, & web security.
Check out these top 3 Drupal hosting services:
- If you need the best shared hosting as solution, click here and get the desired one.


