SlideShare a Scribd company logo
1 of 63
Download to read offline
Gain productivity with Drush

Gain productivity with Drush - Emmanuel Milou

1
Introduction

Gain productivity with Drush - Emmanuel Milou

2
introduction

Emmanuel Milou
@manumilou
emmanuel.milou@savoirfairelinux.com
Drupal Technical Leader at Savoir-faire Linux
Based in Montreal
http://sflx.ca/love
Gain productivity with Drush - Emmanuel Milou

3
What is drush ?

Gain productivity with Drush - Emmanuel Milou

4
what is drush ?

“ Drush (DRUpal Shell) is a command
line shell and scripting interface for
Drupal “

Gain productivity with Drush - Emmanuel Milou

5
what is drush ?



Running Drupal commands through the shell



3 main parts:
●

The drush project manager:
Manage modules and themes
Drush core:
•

●

Manage site configuration
Drush SQL
•

●

•

Issue query to database

Gain productivity with Drush - Emmanuel Milou

6
what is drush ?

$ drush [options] command ... 

Gain productivity with Drush - Emmanuel Milou

7
what is drush ?



Short and long version for every command
●
●
●
●
●
●

site-install (si)
variable-get (vget)
variable-set (vset)
pm-download (dl)
enable (en)
...

Gain productivity with Drush - Emmanuel Milou

8
what is drush ?



Example:
$ drush ­­yes vset maintenance_mode 1
$ drush vset ­­yes maintenance_mode 1
$ drush ­­yes variable­set 
maintenance_mode 1

Gain productivity with Drush - Emmanuel Milou

9
what is drush ?



The help command
$ drush help
$ drush help [command]

Gain productivity with Drush - Emmanuel Milou

10
what is drush ?



Examples:
●
●
●
●
●
●
●

Installing sites
Updating sites
Downloading and enabling modules / themes
Clearing caches
Administring sites configuration
Archiving sites
...

Gain productivity with Drush - Emmanuel Milou

11
Do I need to use drush ?

Gain productivity with Drush - Emmanuel Milou

12
Yes :-)

Gain productivity with Drush - Emmanuel Milou

13
why do I need to use drush



Swiss-knife



Work faster



Automate tasks



Handle multiple sites



Create your own command

Gain productivity with Drush - Emmanuel Milou

14
Installing drush

Gain productivity with Drush - Emmanuel Milou

15
installing drush

https://github.com/drush-ops/drush

Gain productivity with Drush - Emmanuel Milou

16
installing drush



Multi plateform:
●
●

Unix-like OS
Windows

Specific instructions on different platforms:
https://drupal.org/node/1791676

Gain productivity with Drush - Emmanuel Milou

17
installing drush



Example on Ubuntu (need php-pear library)
pear channel­discover  
pear.drush.org
pear install drush/drush
drush version

Gain productivity with Drush - Emmanuel Milou

18
Installing a site and
introspection

Gain productivity with Drush - Emmanuel Milou

19
site installation and instrospection



Download the latest stable release:
$ drush pm­download drupal­7.x



Run installation procedure:
$ drush site­install 
­­db­url=mysql://user:pass@localho
st:port/dbname

Gain productivity with Drush - Emmanuel Milou

20
site installation and instrospection



More on site-install command:
$ drush site­install [profile] 
­­db­url=mysql://user:pass@hostname
[:port]/database
­­site­name=”Dev site”
­­account­mail=admin@mysite.com
­­account­name=admin
­­account­pass=admin

Gain productivity with Drush - Emmanuel Milou

21
site installation and instrospection



After a successful bootstrap
$ drush status



General view of the current installation:
●
●
●
●

Database credentials
Drupal root
Files directory path
Admin theme

Gain productivity with Drush - Emmanuel Milou

22
Downloading and
managing modules

Gain productivity with Drush - Emmanuel Milou

23
downloading and managing modules



Available commands to:
●

●

●

List all modules:
$ drush pm­list
Download a module / theme:
$ drush pm­download <modulename>
Enable a module / theme:
$ drush pm­enable <modulename>

Gain productivity with Drush - Emmanuel Milou

24
downloading and managing modules

Installing and enabling a module used to look
like this:

Gain productivity with Drush - Emmanuel Milou

25
downloading and managing modules
1. Find the module's exact name
2. Look up for the module on drupal.org
3. Download the archive module from project page
4. Go on your disk and extract the archive
5. Copy the module directory in the drupal installation
6. Go to module admin page
7. Realize the module needs an other module to be
enabled
8. Repeat from step 2
Gain productivity with Drush - Emmanuel Milou

26
downloading and managing modules

Now with drush, it is:

Gain productivity with Drush - Emmanuel Milou

27
downloading and managing modules



Find the module's exact name



Run:
$ drush dl <modulename>
$ drush enable <modulename>

Gain productivity with Drush - Emmanuel Milou

28
downloading and managing modules



Download modules in sites/all/modules
­­destination=<path> to override



Specify specific version to download:
●

●

●

Latest dev release:
$ drush dl views ­­dev
List of recent releases: 
$ drush dl views ­­select
Specific version:
$ drush dl 7.x­3.x­dev

Gain productivity with Drush - Emmanuel Milou

29
downloading and managing modules

$ drush en views


Handles module's dependencies by:
●
●

Downloading the required modules
Enabling them

Gain productivity with Drush - Emmanuel Milou

30
downloading and managing modules



Disable a module:
$ drush pm­disable <modulename>



Uninstall a module:
$ drush pm­uninstall <modulename>

Gain productivity with Drush - Emmanuel Milou

31
Updating a site

Gain productivity with Drush - Emmanuel Milou

32
updating a site



One of the most tedious task ever ...



Gets a lot easier with drush:
$ drush pm­update



Core, non-core, modules, security, ...

Gain productivity with Drush - Emmanuel Milou

33
Database management

Gain productivity with Drush - Emmanuel Milou

34
database management



Open a SQL cli, using Drupal's credentials
$ drush sql­cli



Database synchronisation between sites



Run a custom query





$ drush sql­query “SELECT title from 
node where nid=1”
Import SQL statements from a file
$ drush sql­query –file=example.sql

Gain productivity with Drush - Emmanuel Milou

35
database management



Database backup
$ drush sql­dump 
–result­file=dbname.sql –gzip 
●
●

Save to a file
Compress the dump

Gain productivity with Drush - Emmanuel Milou

36
database management



Shortcut for accessing variables table:
$ drush variable­get clean_url



Write is supported:
$ drush variable­set clean_url 0

Gain productivity with Drush - Emmanuel Milou

37
Controlling the cache
and cron

Gain productivity with Drush - Emmanuel Milou

38
controlling the cache and cron



Clear database cache tables
$ drush cc all



Clear a specific cache
views, menu, block, theme-registry, ...
$ drush cc views
●

Gain productivity with Drush - Emmanuel Milou

39
controlling the cache and cron



Run cron
$ drush cron

Gain productivity with Drush - Emmanuel Milou

40
Archiving and restoring site

Gain productivity with Drush - Emmanuel Milou

41
archiving and restoring site



Backup the code, files and database in a
single archive
$ drush archive­dump 
–tar­options="­­exclude=.git 
–exclude=sites/default/files"      
                           

Gain productivity with Drush - Emmanuel Milou

42
archiving and restoring site



Restore an archive
$ drush archive­restore file       
                          

Gain productivity with Drush - Emmanuel Milou

43
Drush aliases

Gain productivity with Drush - Emmanuel Milou

44
drush aliases





Run drush commands on other local or
remote Drupal installations
Site aliases:
●
●

@self: current installation
Custom:
•
@dev
•
@staging
•
@prod

Gain productivity with Drush - Emmanuel Milou

45
drush aliases



Shortcut:
$ drush 
­­uri=”camp2013.drushdemo.staging” 
­­root=”/home/manu/dev/drupal/camp
2013/staging/src/drupal” status
becomes:
$ drush @dev status

Gain productivity with Drush - Emmanuel Milou

46
drush aliases
<?php
/**
* Drush aliases definition
*/
$aliases['staging'] = array(
'root' => '/var/www/staging',
'uri' => 'staging.bibliopoly.sfl.net',
'remote-host' =>'staging.bibliopoly.sfl.net',
'remote-user' => 'webmaster',
'path-aliases' => array(
'%files' => 'sites/default/files',
),
);
$aliases['prod'] = array(
'root' => '/var/www/prod',
'uri' => 'live.bibliopoly.sfl.net',
'remote-host' =>'live.bibliopoly.sfl.net',
'remote-user' => 'webmaster',
'path-aliases' => array(
'%files' => 'sites/default/files',
),
);
Gain productivity with Drush - Emmanuel Milou

47
drush aliases

drush status == drush @self status


The simplest example:
$ drush @prod status



More advanced:
$ drush sql­sync @prod @dev
$ drush rsync @staging @prod
$ drush rsync @prod:%files        
@staging:%files

Gain productivity with Drush - Emmanuel Milou

48
drush aliases

Documentation:
http://drupalcontrib.org/api/drupal/contribu
tions!drush!examples!example.aliases.drushrc
.php/7

Gain productivity with Drush - Emmanuel Milou

49
Third-party integration

Gain productivity with Drush - Emmanuel Milou

50
Third-party integration



3 easy steps to create a custom drush
command:
●

●

●

Create a command file called
COMMANDFILE.drush.inc
Implement the function
COMMANDFILE_drush_command()
Implement the functions that your
command will call

Gain productivity with Drush - Emmanuel Milou

51
Third-party integration



Drush searches for commandfiles in the
following location:
●

The “/path/to/drush/command” folder

●

Folders listed in the “include” folder

●

●

●

●

The system-wide drush commands folder, e.g.
/usr/share/drush/commands
The ".drush" folder in the user's HOME folder
/drush and /sites/all/drush in the current Drupal
installation
All enabled modules in the current Drupal installation

Gain productivity with Drush - Emmanuel Milou

52
Third-party integration



Complete documentation:
$ drush topic docs­commands

Gain productivity with Drush - Emmanuel Milou

53
Third-party integration



Custom module integration
●

●

●

Create a file called
MODULENAME.drush.inc in the module
directory
Add the reference in MODULENAME.info
•
files[] = MODULENAME.drush.inc
Implement hook_drush_command()
•
MODULENAME_drush_command()

Gain productivity with Drush - Emmanuel Milou

54
Third-party integration



devel_generate module
●



views module
●



Enable, disable, list, revert views, ...

features module
●



Generate content, users, terms, ...

Create, export, revert features, ...

coder_review module
●

Run code reviews

Gain productivity with Drush - Emmanuel Milou

55
Example: deploying a site

Gain productivity with Drush - Emmanuel Milou

56
Example: deploying a site

(1) Put production site in maintenance
(2) Sync files from the staging env to
production
(3) Run any pending database updates on the
production site
(4) Clear the cache on production
(5) Put production site back online
Gain productivity with Drush - Emmanuel Milou

57
Example: deploying a site



The perfect setup:






Continuous-integration server: Jenkins
Source code management: git
A development environment
A staging environment
A production environment

Gain productivity with Drush - Emmanuel Milou

58
Example: deploying a site





Source code changes are pushed from dev
into git repository
Jenkins polls the git repository for new
commits



Jenkins checkout latest revision



Jenkins runs automatic tests



Jenkins deploys latest revision to the staging
environment if tests passed

Gain productivity with Drush - Emmanuel Milou

59
Example: deploying a site

$ drush ­­yes @prod vset maintenance_mode 1
$ drush ­­yes rsync –verbose @staging @prod
$ drush ­­yes @prod updatedb
$ drush @prod clear­cache all
$ drush ­­yes @prod vset maintenance_mode 0

Gain productivity with Drush - Emmanuel Milou

60
Example: deploying a site



Code synchronisation:
✗

@prod -> @staging

✔

@staging -> @prod Files synchronisation:
✗



Database
synchronisation:
✗

✔

@prod -> @staging

@staging -> @prod

✔

@staging -> @prod

@prod -> @staging

Gain productivity with Drush - Emmanuel Milou

61
Thank you :-)
And don't forget to get a badge ...

Gain productivity with Drush - Emmanuel Milou

62
Gain productivity with Drush - Emmanuel Milou

63

More Related Content

Similar to Gain productivity with Drush (Drupal Camp, Montreal 2013)

Travis Carden/Drupal Nebraks: Drush Presentation
Travis Carden/Drupal Nebraks: Drush PresentationTravis Carden/Drupal Nebraks: Drush Presentation
Travis Carden/Drupal Nebraks: Drush PresentationDrupal Nebraska
 
Drush A beginners guide to a advanced tool.
Drush A beginners guide to a advanced tool.Drush A beginners guide to a advanced tool.
Drush A beginners guide to a advanced tool.Mediacurrent
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonChris Charlton
 
A Drush Primer - DrupalCamp Chattanooga 2013
A Drush Primer - DrupalCamp Chattanooga 2013A Drush Primer - DrupalCamp Chattanooga 2013
A Drush Primer - DrupalCamp Chattanooga 2013Chris Hales
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?Sergei Stryukov
 
Drush and drupal. администрирование. Волчек Михаил
Drush and drupal. администрирование. Волчек МихаилDrush and drupal. администрирование. Волчек Михаил
Drush and drupal. администрирование. Волчек МихаилPVasili
 
Drush and drupal. администрирование волчек михаил
Drush and drupal. администрирование  волчек михаилDrush and drupal. администрирование  волчек михаил
Drush and drupal. администрирование волчек михаилdrupalconf
 
Drush&drupal. administration
Drush&drupal. administrationDrush&drupal. administration
Drush&drupal. administrationzabej
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupalDay
 
Improving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAImproving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAJesus Manuel Olivas
 
Face your fears: Drush and Aegir
Face your fears: Drush and AegirFace your fears: Drush and Aegir
Face your fears: Drush and AegirIztok Smolic
 
Drush to simplify Drupalers work - Sivaji
Drush to simplify Drupalers work - SivajiDrush to simplify Drupalers work - Sivaji
Drush to simplify Drupalers work - SivajiDrupal Camp Delhi
 
drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010Florian Latzel
 
Exploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molinaExploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molinaSalvador Molina (Slv_)
 
Automating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondAutomating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondNuvole
 
Drush und Multisite: drush_multi
Drush und Multisite: drush_multiDrush und Multisite: drush_multi
Drush und Multisite: drush_multiFlorian Latzel
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and moreAcquia
 
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Jeff Geerling
 

Similar to Gain productivity with Drush (Drupal Camp, Montreal 2013) (20)

Travis Carden/Drupal Nebraks: Drush Presentation
Travis Carden/Drupal Nebraks: Drush PresentationTravis Carden/Drupal Nebraks: Drush Presentation
Travis Carden/Drupal Nebraks: Drush Presentation
 
Drush A beginners guide to a advanced tool.
Drush A beginners guide to a advanced tool.Drush A beginners guide to a advanced tool.
Drush A beginners guide to a advanced tool.
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
 
A Drush Primer - DrupalCamp Chattanooga 2013
A Drush Primer - DrupalCamp Chattanooga 2013A Drush Primer - DrupalCamp Chattanooga 2013
A Drush Primer - DrupalCamp Chattanooga 2013
 
Intro to Drush
Intro to DrushIntro to Drush
Intro to Drush
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?
 
Drush and drupal. администрирование. Волчек Михаил
Drush and drupal. администрирование. Волчек МихаилDrush and drupal. администрирование. Волчек Михаил
Drush and drupal. администрирование. Волчек Михаил
 
Drush and drupal. администрирование волчек михаил
Drush and drupal. администрирование  волчек михаилDrush and drupal. администрирование  волчек михаил
Drush and drupal. администрирование волчек михаил
 
Drush&drupal. administration
Drush&drupal. administrationDrush&drupal. administration
Drush&drupal. administration
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
Improving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAImproving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLA
 
Face your fears: Drush and Aegir
Face your fears: Drush and AegirFace your fears: Drush and Aegir
Face your fears: Drush and Aegir
 
Drush to simplify Drupalers work - Sivaji
Drush to simplify Drupalers work - SivajiDrush to simplify Drupalers work - Sivaji
Drush to simplify Drupalers work - Sivaji
 
drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010
 
Drush
DrushDrush
Drush
 
Exploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molinaExploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molina
 
Automating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondAutomating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyond
 
Drush und Multisite: drush_multi
Drush und Multisite: drush_multiDrush und Multisite: drush_multi
Drush und Multisite: drush_multi
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
 
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
 

Recently uploaded

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Gain productivity with Drush (Drupal Camp, Montreal 2013)

  • 1. Gain productivity with Drush Gain productivity with Drush - Emmanuel Milou 1
  • 2. Introduction Gain productivity with Drush - Emmanuel Milou 2
  • 3. introduction Emmanuel Milou @manumilou emmanuel.milou@savoirfairelinux.com Drupal Technical Leader at Savoir-faire Linux Based in Montreal http://sflx.ca/love Gain productivity with Drush - Emmanuel Milou 3
  • 4. What is drush ? Gain productivity with Drush - Emmanuel Milou 4
  • 5. what is drush ? “ Drush (DRUpal Shell) is a command line shell and scripting interface for Drupal “ Gain productivity with Drush - Emmanuel Milou 5
  • 6. what is drush ?  Running Drupal commands through the shell  3 main parts: ● The drush project manager: Manage modules and themes Drush core: • ● Manage site configuration Drush SQL • ● • Issue query to database Gain productivity with Drush - Emmanuel Milou 6
  • 7. what is drush ? $ drush [options] command ...  Gain productivity with Drush - Emmanuel Milou 7
  • 8. what is drush ?  Short and long version for every command ● ● ● ● ● ● site-install (si) variable-get (vget) variable-set (vset) pm-download (dl) enable (en) ... Gain productivity with Drush - Emmanuel Milou 8
  • 9. what is drush ?  Example: $ drush ­­yes vset maintenance_mode 1 $ drush vset ­­yes maintenance_mode 1 $ drush ­­yes variable­set  maintenance_mode 1 Gain productivity with Drush - Emmanuel Milou 9
  • 10. what is drush ?  The help command $ drush help $ drush help [command] Gain productivity with Drush - Emmanuel Milou 10
  • 11. what is drush ?  Examples: ● ● ● ● ● ● ● Installing sites Updating sites Downloading and enabling modules / themes Clearing caches Administring sites configuration Archiving sites ... Gain productivity with Drush - Emmanuel Milou 11
  • 12. Do I need to use drush ? Gain productivity with Drush - Emmanuel Milou 12
  • 13. Yes :-) Gain productivity with Drush - Emmanuel Milou 13
  • 14. why do I need to use drush  Swiss-knife  Work faster  Automate tasks  Handle multiple sites  Create your own command Gain productivity with Drush - Emmanuel Milou 14
  • 15. Installing drush Gain productivity with Drush - Emmanuel Milou 15
  • 17. installing drush  Multi plateform: ● ● Unix-like OS Windows Specific instructions on different platforms: https://drupal.org/node/1791676 Gain productivity with Drush - Emmanuel Milou 17
  • 18. installing drush  Example on Ubuntu (need php-pear library) pear channel­discover   pear.drush.org pear install drush/drush drush version Gain productivity with Drush - Emmanuel Milou 18
  • 19. Installing a site and introspection Gain productivity with Drush - Emmanuel Milou 19
  • 20. site installation and instrospection  Download the latest stable release: $ drush pm­download drupal­7.x  Run installation procedure: $ drush site­install  ­­db­url=mysql://user:pass@localho st:port/dbname Gain productivity with Drush - Emmanuel Milou 20
  • 21. site installation and instrospection  More on site-install command: $ drush site­install [profile]  ­­db­url=mysql://user:pass@hostname [:port]/database ­­site­name=”Dev site” ­­account­mail=admin@mysite.com ­­account­name=admin ­­account­pass=admin Gain productivity with Drush - Emmanuel Milou 21
  • 22. site installation and instrospection  After a successful bootstrap $ drush status  General view of the current installation: ● ● ● ● Database credentials Drupal root Files directory path Admin theme Gain productivity with Drush - Emmanuel Milou 22
  • 23. Downloading and managing modules Gain productivity with Drush - Emmanuel Milou 23
  • 24. downloading and managing modules  Available commands to: ● ● ● List all modules: $ drush pm­list Download a module / theme: $ drush pm­download <modulename> Enable a module / theme: $ drush pm­enable <modulename> Gain productivity with Drush - Emmanuel Milou 24
  • 25. downloading and managing modules Installing and enabling a module used to look like this: Gain productivity with Drush - Emmanuel Milou 25
  • 26. downloading and managing modules 1. Find the module's exact name 2. Look up for the module on drupal.org 3. Download the archive module from project page 4. Go on your disk and extract the archive 5. Copy the module directory in the drupal installation 6. Go to module admin page 7. Realize the module needs an other module to be enabled 8. Repeat from step 2 Gain productivity with Drush - Emmanuel Milou 26
  • 27. downloading and managing modules Now with drush, it is: Gain productivity with Drush - Emmanuel Milou 27
  • 28. downloading and managing modules  Find the module's exact name  Run: $ drush dl <modulename> $ drush enable <modulename> Gain productivity with Drush - Emmanuel Milou 28
  • 29. downloading and managing modules  Download modules in sites/all/modules ­­destination=<path> to override  Specify specific version to download: ● ● ● Latest dev release: $ drush dl views ­­dev List of recent releases:  $ drush dl views ­­select Specific version: $ drush dl 7.x­3.x­dev Gain productivity with Drush - Emmanuel Milou 29
  • 30. downloading and managing modules $ drush en views  Handles module's dependencies by: ● ● Downloading the required modules Enabling them Gain productivity with Drush - Emmanuel Milou 30
  • 31. downloading and managing modules  Disable a module: $ drush pm­disable <modulename>  Uninstall a module: $ drush pm­uninstall <modulename> Gain productivity with Drush - Emmanuel Milou 31
  • 32. Updating a site Gain productivity with Drush - Emmanuel Milou 32
  • 33. updating a site  One of the most tedious task ever ...  Gets a lot easier with drush: $ drush pm­update  Core, non-core, modules, security, ... Gain productivity with Drush - Emmanuel Milou 33
  • 34. Database management Gain productivity with Drush - Emmanuel Milou 34
  • 35. database management  Open a SQL cli, using Drupal's credentials $ drush sql­cli  Database synchronisation between sites  Run a custom query   $ drush sql­query “SELECT title from  node where nid=1” Import SQL statements from a file $ drush sql­query –file=example.sql Gain productivity with Drush - Emmanuel Milou 35
  • 36. database management  Database backup $ drush sql­dump  –result­file=dbname.sql –gzip  ● ● Save to a file Compress the dump Gain productivity with Drush - Emmanuel Milou 36
  • 37. database management  Shortcut for accessing variables table: $ drush variable­get clean_url  Write is supported: $ drush variable­set clean_url 0 Gain productivity with Drush - Emmanuel Milou 37
  • 38. Controlling the cache and cron Gain productivity with Drush - Emmanuel Milou 38
  • 39. controlling the cache and cron  Clear database cache tables $ drush cc all  Clear a specific cache views, menu, block, theme-registry, ... $ drush cc views ● Gain productivity with Drush - Emmanuel Milou 39
  • 40. controlling the cache and cron  Run cron $ drush cron Gain productivity with Drush - Emmanuel Milou 40
  • 41. Archiving and restoring site Gain productivity with Drush - Emmanuel Milou 41
  • 42. archiving and restoring site  Backup the code, files and database in a single archive $ drush archive­dump  –tar­options="­­exclude=.git  –exclude=sites/default/files"                                   Gain productivity with Drush - Emmanuel Milou 42
  • 43. archiving and restoring site  Restore an archive $ drush archive­restore file                                   Gain productivity with Drush - Emmanuel Milou 43
  • 44. Drush aliases Gain productivity with Drush - Emmanuel Milou 44
  • 45. drush aliases   Run drush commands on other local or remote Drupal installations Site aliases: ● ● @self: current installation Custom: • @dev • @staging • @prod Gain productivity with Drush - Emmanuel Milou 45
  • 47. drush aliases <?php /** * Drush aliases definition */ $aliases['staging'] = array( 'root' => '/var/www/staging', 'uri' => 'staging.bibliopoly.sfl.net', 'remote-host' =>'staging.bibliopoly.sfl.net', 'remote-user' => 'webmaster', 'path-aliases' => array( '%files' => 'sites/default/files', ), ); $aliases['prod'] = array( 'root' => '/var/www/prod', 'uri' => 'live.bibliopoly.sfl.net', 'remote-host' =>'live.bibliopoly.sfl.net', 'remote-user' => 'webmaster', 'path-aliases' => array( '%files' => 'sites/default/files', ), ); Gain productivity with Drush - Emmanuel Milou 47
  • 48. drush aliases drush status == drush @self status  The simplest example: $ drush @prod status  More advanced: $ drush sql­sync @prod @dev $ drush rsync @staging @prod $ drush rsync @prod:%files         @staging:%files Gain productivity with Drush - Emmanuel Milou 48
  • 50. Third-party integration Gain productivity with Drush - Emmanuel Milou 50
  • 51. Third-party integration  3 easy steps to create a custom drush command: ● ● ● Create a command file called COMMANDFILE.drush.inc Implement the function COMMANDFILE_drush_command() Implement the functions that your command will call Gain productivity with Drush - Emmanuel Milou 51
  • 52. Third-party integration  Drush searches for commandfiles in the following location: ● The “/path/to/drush/command” folder ● Folders listed in the “include” folder ● ● ● ● The system-wide drush commands folder, e.g. /usr/share/drush/commands The ".drush" folder in the user's HOME folder /drush and /sites/all/drush in the current Drupal installation All enabled modules in the current Drupal installation Gain productivity with Drush - Emmanuel Milou 52
  • 54. Third-party integration  Custom module integration ● ● ● Create a file called MODULENAME.drush.inc in the module directory Add the reference in MODULENAME.info • files[] = MODULENAME.drush.inc Implement hook_drush_command() • MODULENAME_drush_command() Gain productivity with Drush - Emmanuel Milou 54
  • 55. Third-party integration  devel_generate module ●  views module ●  Enable, disable, list, revert views, ... features module ●  Generate content, users, terms, ... Create, export, revert features, ... coder_review module ● Run code reviews Gain productivity with Drush - Emmanuel Milou 55
  • 56. Example: deploying a site Gain productivity with Drush - Emmanuel Milou 56
  • 57. Example: deploying a site (1) Put production site in maintenance (2) Sync files from the staging env to production (3) Run any pending database updates on the production site (4) Clear the cache on production (5) Put production site back online Gain productivity with Drush - Emmanuel Milou 57
  • 58. Example: deploying a site  The perfect setup:      Continuous-integration server: Jenkins Source code management: git A development environment A staging environment A production environment Gain productivity with Drush - Emmanuel Milou 58
  • 59. Example: deploying a site   Source code changes are pushed from dev into git repository Jenkins polls the git repository for new commits  Jenkins checkout latest revision  Jenkins runs automatic tests  Jenkins deploys latest revision to the staging environment if tests passed Gain productivity with Drush - Emmanuel Milou 59
  • 60. Example: deploying a site $ drush ­­yes @prod vset maintenance_mode 1 $ drush ­­yes rsync –verbose @staging @prod $ drush ­­yes @prod updatedb $ drush @prod clear­cache all $ drush ­­yes @prod vset maintenance_mode 0 Gain productivity with Drush - Emmanuel Milou 60
  • 61. Example: deploying a site  Code synchronisation: ✗ @prod -> @staging ✔ @staging -> @prod Files synchronisation: ✗  Database synchronisation: ✗ ✔ @prod -> @staging @staging -> @prod ✔ @staging -> @prod @prod -> @staging Gain productivity with Drush - Emmanuel Milou 61
  • 62. Thank you :-) And don't forget to get a badge ... Gain productivity with Drush - Emmanuel Milou 62
  • 63. Gain productivity with Drush - Emmanuel Milou 63