Useful Drush commands | Drupal 8

Useful Drush commands

Submitted by editor on Mon, 01/11/2016 - 16:28

To handle drupal with drust, First of all, you must install drush, and execute drush command from your drupal instalation folder.

  • For default or single site instalation, just put on drupal root folder (Ex : /var/www/drupal8)
  • For Multi sites, put in to the site folder (Ex : /var/www/drupal8/sites/mysite1)

 

First command : Status
drush status

Download and active a module
drush en module_name -y

Clear All Cache
On D7 # drush cc all
On D8 # drush cr

Get a user login url ( Tempory)
drush uli
drush uli [user_id]
#Set a user password (Here : USER=admin)
drush upwd --password="new admin password" "admin"

Set / Change User password
drush upwd USERNAME --password="The_New_Password"
Example : drush upwd admin --password=admin

Set / Get Variable and configuration

Drupal 7
variable-set (vset)
drush vset variable_name value
Example : drush variable-set stage_file_proxy_origin "http://www.drupal8.ovh"

Drupal 8
config-set
drush config-set config_name field value
Example : drush config-set stage_file_proxy.settings origin 'http://www.drupal8.ovh' -y

 

Install drupal from drush

drush dl drupal --drupal-project-rename=example
cd example
drush site-install standard --db-url='mysql://[db_user]:[db_pass]@localhost/[db_name]'
Options
--site-name=Example --account-name=admin --account-pass=adminpassword

Example 2 : Install drupal 8 using sqlite database
drush site-install standard --db-url='sqlite://sites/default/files/.ht.db.sqlite' --site-name=D8 --account-name=admin --account-pass=admin --notify=0 --account-mail=name@mail.com

Enable few usefull contrib modules.

drush en workbench workbench_moderation youtube imce linkit captcha honeypot securelogin pathauto -y
drush en admin_toolbar admin_toolbar_tools -y

Enable drupal development modules.

drush en devel kint coffee features features_ui -y

 

Update disabled modules using Drush

The option --check-disabled Check for updates of disabled modules and themes. This allow you to update modules and themes codes even disabled.
The option --lock allow to exclude a module
Example :
drush up; # Update codes and database
drush upc; # Update codes only
drush updb; # Update database only

drush pm-update --lock=MODULE_TO_EXCLUDE
drush pm-updatecode --check-disabled
#OR, shortcut :
drush upc --check-disabled

NOTE :  To avoid accidentally update and show the list before update, Do not use the option -y.

 

Get Set Variables / State (set-state / get-state)

Put the site in maintenance mode : Put Site Online / Offline
drush sset system.maintenance_mode 1 // To set
drush sget system.maintenance_mode // To check
drush sset system.maintenance_mode 0 // To Exit maintenance mode
Linke on drupal 7 : drush vset maintenance_mode 1

Get / Set Configuration

#Get site title
drush cget system.site
#Get front page
drush cget system.site page.front
#Set front page
drush config-set system.site page.front my-new-front-page
#Set a custom config's value. Ex:  configname=mumodule.settings, key is ['site']['section']['page']['title'] = 'My page title'
drush cset mumodule.settings site.section.page.title 'My page title'

(http://drushcommands.com/drush-8x/core/site-install/ for More info)

Update Database (/update.php)
drush updatedb

http://drushcommands.com/

Comments

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.