Drush is a command line shell and scripting interface for Drupal that allows users to perform common site building tasks faster and easier than through the web interface. Drush provides commands to download, update, and manage Drupal sites and modules from the command line. It also supports aliases to define multiple sites, custom commands, and scripting functionality to automate repetitive tasks.
2. What is Drush?
- drush is a command line interface that allows to
manage your Drupal web sites fast and easy.
- drush is not a module;
- drush = drupal + shell = drupal in the command line;
3. Why Drush?
- saves your time;
- possibility to use drush in scripts;
- custom drush commands.
- aliases;
4. The Manual Method The Drush Method
Drush: More Beer, Less Effort
- go to the drupal.org and search
necessary module;
- drush dl views -y && drush en views -y
- download module;
- find archive and unzip it;
- copy module to the Drupal repository;
- go to the site, search module and enable it.
- go to beer
6. Aliases
- aliases of the sites are shortcuts that point to some
of
the sites for which you want to execute the command- use in our scripts
How to create alias?
- go to the user directore: cd ~
<?php
$aliases['example'] = array(
'uri' => 'localhost',
'root' => "/var/www/example.loc",
);
- create file for aliases:
.drush/aliases.drushrc.php
drush @example status
7. Drush in scripts
// Just some ideas to get the juices flowing.
drush_print_r(user_roles());
drush_print_r($GLOBALS['user']);
drush php-script scratch.php
alan@alan-eMachines-E525:~$ drush php-script
/usr/share/php/drush/commands/core/scratch.php
alan@alan-eMachines-E525:~$
8. How to create custom script?<?php
$aliases = array('@example', '@example_1', '@example_n');
foreach ($aliases as $alias) {
$status = shell_exec("drush $alias status");
drush_print_r($status);
}
alan@alan-eMachines-E525:~$ drush php-script
/usr/share/php/drush/commands/core/scratch.php
/usr/share/php/drush/commands/core/my-script.php
alan@alan-eMachines-E525:~$
alan@alan-eMachines-E525:~$ sudo drush php-script my-script
Drupal version : 7.26
Site URI : localhost
Database driver : mysql
Database hostname : localhost
Database username : root
...