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 variableset
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
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
18. installing drush
Example on Ubuntu (need php-pear library)
pear channeldiscover
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 pmdownload drupal7.x
Run installation procedure:
$ drush siteinstall
dburl=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 siteinstall [profile]
dburl=mysql://user:pass@hostname
[:port]/database
sitename=”Dev site”
accountmail=admin@mysite.com
accountname=admin
accountpass=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
24. downloading and managing modules
Available commands to:
●
●
●
List all modules:
$ drush pmlist
Download a module / theme:
$ drush pmdownload <modulename>
Enable a module / theme:
$ drush pmenable <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.x3.xdev
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 pmdisable <modulename>
Uninstall a module:
$ drush pmuninstall <modulename>
Gain productivity with Drush - Emmanuel Milou
31
33. updating a site
One of the most tedious task ever ...
Gets a lot easier with drush:
$ drush pmupdate
Core, non-core, modules, security, ...
Gain productivity with Drush - Emmanuel Milou
33
35. database management
Open a SQL cli, using Drupal's credentials
$ drush sqlcli
Database synchronisation between sites
Run a custom query
$ drush sqlquery “SELECT title from
node where nid=1”
Import SQL statements from a file
$ drush sqlquery –file=example.sql
Gain productivity with Drush - Emmanuel Milou
35
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
42. archiving and restoring site
Backup the code, files and database in a
single archive
$ drush archivedump
–taroptions="exclude=.git
–exclude=sites/default/files"
Gain productivity with Drush - Emmanuel Milou
42
43. archiving and restoring site
Restore an archive
$ drush archiverestore file
Gain productivity with Drush - Emmanuel Milou
43
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
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
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 clearcache all
$ drush yes @prod vset maintenance_mode 0
Gain productivity with Drush - Emmanuel Milou
60