Your SlideShare is downloading. ×
A Drush Primer - DrupalCamp Chattanooga 2013
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

A Drush Primer - DrupalCamp Chattanooga 2013


Published on

Drush Primer session slides from my presentation at DrupalCamp Chattanooga which on November 9th, 2013.

Drush Primer session slides from my presentation at DrupalCamp Chattanooga which on November 9th, 2013.

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. A Drush Primer DrupalCamp Chattanooga 2013
  • 2. Chris Hales DevOps Manager Twitter: @chris_hales IRC: chales
  • 3. @Mediacurrent Not on the Agenda ● ● ● ● General Drupal administration How to use the terminal How to install Drush (RTFM) Really deep dive examples (well, just a few)
  • 4. @Mediacurrent Agenda ● ● ● ● ● ● ● ● What is Drush? Some history Basic use Simple commands to make your life easier Drush aliases Advanced commands Custom combinations Drush Make
  • 5. Drush Well over 889,000 downloads Integration with 276+ modules Packages available for most systems
  • 6. What is Drush?
  • 7. “A command line shell and scripting interface for Drupal.”
  • 8. @Mediacurrent What is it? The main focus of Drush is to take complex commands that you could perform within the terminal and shorten them into simplified and easy to remember commands. rsync -vldkogDtprz ssh root@ /var/www/drupal/sites/default/files /local/www/drupal/sites/default/files Or if you use Drush with an alias setup for your dev site you can use the following command. $ drush rsync @mysite.local:%files
  • 9. @Mediacurrent History Drush is a command line utility to assist in Drupal site building, maintenance and administration tasks. It is a Drupal contrib project but it’s not a module. On *nix systems it’s run as a shell script or a bat on Windows. The guts are written in PHP so most Drupal developers should understand the inner workings. The first commit to the project was made on Nov 12, 2006 by Arto Bendiken. He made the first few commits that started the 4.x release. Drupal legend Moshe Weitzman has been the primary maintainer for the past few years but he’s had a lot of help. At this time there are 165 contributors to the project.
  • 10. @Mediacurrent History The current version of Drush is version 7 which is compatible with Drupal 6, 7 and 8. The Drush project moved to Github in August 2013 however you can still find general info on the original Drupal hosted project page. Look for Drush at it’s new home on Github
  • 11. The Basics
  • 12. @Mediacurrent Getting Help Review the Drush documentation online Resources on Drush itself has a very extensive help system $ drush --help $ drush help <command> And don’t forget Google is your friend!
  • 13. @Mediacurrent The Basics To use Drush with remote hosts you must use SSH keys! Drush can perform some commands against remote sites without the need for Drush to be installed on the remote. You must be within the context of a fully functional Drupal site to use most commands. For multisites drill into the site directory with the settings.php file of the site you wish to work with. If you see the following error you are not within a functional site. Command <command> needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command. [error] A Drupal installation directory could not be found
  • 14. @Mediacurrent Commands The main command structure usually looks like this. $ drush <cmd> [[arg1] [arg2]...] [[option1] [option2]...] Drush commands are usually in the form of $ drush <command> <from site> <to site> Common options that remove interaction. -y(es) -n(o) $ drush <command> <from site> <to site> -y
  • 15. @Mediacurrent Common Tasks Here are a few of the common admin tasks. ● ● ● ● ● ● ● Clear caches Install modules Update modules Run update.php Update configuration settings Manual cron runs Updating users
  • 16. @Mediacurrent Site Status Check your site status. $ cd /path/to/drupal/docroot $ drush st Drupal version Site URI Database driver Database username Database password Database name Database Drupal bootstrap Drupal user : : : : : : : : : 6.28 mysqli user pass ag_www Connected Successful Anonymous
  • 17. @Mediacurrent Site Status Default theme : mytheme Administration theme : seven Administration theme : seven PHP executable : /path/to/php PHP configuration : /path/to/conf/php.ini PHP OS : Darwin Drush version : 6.0 Drush configuration : "/path/to/drush/drushrc.php" Drush alias files : ~/.drush/my.drushrc.php Drupal root : /path/to/docroot Site path : sites/ File directory path : sites/default/files Temporary file directory path : /tmp
  • 18. @Mediacurrent Clearing Cache Clearing caches. $ cd /path/to/drupal/docroot $ drush cc Enter a number to choose which cache to clear. [0] : Cancel [1] : all [2] : drush [3] : theme-registry [4] : menu [5] : css-js [6] : block [7] : module-list [8] : theme-list [9] : registry [10] : views
  • 19. @Mediacurrent Clearing Cache Clear all caches. $ cd /path/to/drupal/docroot $ drush cc all 'all' cache was cleared in mysite.local [success] Clear just a specific cache such as the CSS/JS cache $ cd /path/to/drupal/docroot $ drush cc css-js 'css-js' cache was cleared in mysite.local [success]
  • 20. @Mediacurrent Install Modules Download the module. $ cd /path/to/drupal/docroot $ drush dl schema Project schema (6.x-1.7) downloaded to sites/all/modules/contrib/schema. [success] Then enable the module. $ drush en schema schema was enabled successfully. You can also combine the commands. $ drush dl scheme && drush en schema -y [ok]
  • 21. @Mediacurrent Update Modules View a list of available module updates. (output abbreviated) $ cd /path/to/drupal/docroot $ drush up Name context ctools features filefield Installed Version 6.x-3.1 6.x-1.10+2-dev 6.x-1.x-dev 6.x-3.10 Proposed version Message 6.x-3.3 SECURITY UPDATE available 6.x-1.0 Update available 6.x-1.2 Update available 6.x-3.11 Update available Do you really want to continue with the update process? (y/n):
  • 22. @Mediacurrent Update Modules Update one or more modules by specifying them. The new version will be downloaded, any database updates executed and caches cleared. (output abbreviated) $ cd /path/to/drupal/docroot $ drush up context features Do you really want to continue with the update process? (y/n): y Project context was updated successfully. Installed version is now 6.x-3.3. Backups were saved into the directory /backups/context. [ok] 'all' cache was cleared in mysite.local [success] No database updates required [success] 'all' cache was cleared in mysite.local [success] Finished performing updates. [ok]
  • 23. Advanced
  • 24. @Mediacurrent Drush Aliases Drush aliases allow your to target the context of a site much easier. $ cd /path/to/drupal/docroot $ drush sa --full --with-optional @self $aliases["self"] = array ( 'root' => '/path/to/site/docroot', 'uri' => 'http://default', '#name' => 'self', 'path-aliases' => array ( '%drush' => '/path/to/php/drush', '%site' => 'sites/default/', ), );
  • 25. @Mediacurrent Drush Aliases Once you create an alias file and name the sites you wish to interact with you can target the sites’ context and run any command against it. For a full featured alais template you can use mine as a starting point, Download a module to the local site. $ drush @mysite.local dl admin_menu Check production status. $ drush st Clear caches on the staging site. $ drush @mysite.stage cc all
  • 26. @Mediacurrent Drush Aliases Now you can use alias shortcuts to perform commands such as syncing your local site to the production site. Sync the files in sites/default/files using the files path alias. $ drush rsync @mysite.local:%files Sync the database using sql-sync. $ drush sql-sync @mysite.local
  • 27. @Mediacurrent Database Dumps Backup a database. $ drush sql-dump --result-file=dump.sql Backup a database using gzip compression. $ drush sql-dump --gzip --result-file=dump.sql.gz Similar but you can just use the command output and write it to a file. $ drush sql-dump > /path/to/dump/file.sql To restore this dump file you can use the Drush sql-query command. $ drush sqlq < /path/to/dump/file.sql
  • 28. @Mediacurrent Site Install You can install a full Drupal site. $ cd /path/to/drupal/docroot $ drush si --db-url=mysql://root:root@ --account-pass=abc123 (assumes you have a database setup already) If you need to add the database you can also use the superuser options which will then create the database as well. --db-su=name --db-su-pw=password --accountpass=myadminpass
  • 29. @Mediacurrent Variables List all available variables. $ drush variable-get Set maintenance mode. $ drush variable-set maintenance_mode 1 maintenance_mode was set to "1". [success] Disable maintenance mode. $ drush variable-set maintenance_mode 0 maintenance_mode was set to "0". [success]
  • 30. Thank You! Questions? @chris_hales