How to Manage Drupal 8 Web Servers Using Drush


Introduction: The Most Popular CLI Tool for Drupal 8

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 Drupal 8 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.

Step One: Install Drush on the Web Server (Linux or Windows)

Follow this HostAdvice Tutorial in order to install Drush on CentOS using Sudo:

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.

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.

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.

Step Two: Use Drush to Install Drupal 8 Core

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

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

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 Three: Use Drush to Install Drupal 8 Modules

Drush is preferred by professional Drupal 8 administrators, programmers, & developers because it can speed up common repetitive tasks related to maintenance or installation.

To download a Drupal 8 module by Drush command:

drush dl module_name

To install a Drupal 8 module using Drush, use the CLI to run:

drush en module_name

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 Four: Use Drush to Install Drupal 8 Themes

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.

Download a Drupal 8 theme:

$ drush dl themename

Enable the theme:

$ drush en themename

List of all installed themes:

$ drush pm-list --type=theme

Set the theme to be default:

$ drush config-set system.theme default themename

Set the theme to be administration section use:

$ drush config-set system.theme admin themename

Other useful Drush commands are for clearing the theme cache:

$ drush cr

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 Five: Use Drush to Update Drupal 8 Projects

Another major use of Drush is in automating regular Drupal maintenance tasks like security updates, module upgrades, patches, & code versions with the command line.

To list all available project updates (requires Composer):

composer outdated 'drupal/*'

List all security updates:

drushpm:security

Install all module/theme updates (requires Composer):

composer update drupal/modulename --with-dependencies

Run any database updates:

drush updatedb

Rebuild the site cache:

drush cr

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

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.

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:

Was this article helpful?