Drush configuration is in the file drushrc.php. It can be located in the following locations:
- In the website configuration directory: for example sites/default/drushrc.php
- In the directory sites/all/drush/drushrc.php
- In each directory specified by the option --config (-c)
- In the user directory .drush: for example ~/.drush/.drushrc.php
- In the system configuration directory: for example /etc/drush/drushrc.php
- In the directory where you installed Drush.
This file can be found here.
If Drush finds the file in several locations above, parameters will be unified in merged configuration arrays. If your configuration is designed for a specific version of Drush, you can rename the file to include the version number: drush[VERSION]rc.php. For example, for Drush 5, the file will be called drush5rc.php.
Now let’s look at some examples of configuration, to facilitate the development.
Example 1: Update the Git repository
In general, to update its local Git repository from the remote server, this command is used:
git pull origin branch
Add the following line in the file drushrc.php
$options['shell-aliases']['pull'] = '!git pull origin branch';
We can now update the Git repository with the following command:
Example 2: Enable / Disable the maintenance mode
To enable or disable the website, the configuration file should contain the following two options:
$options['shell-aliases']['offline'] = 'variable-set -y --always-set maintenance_mode 1';
$options['shell-aliases']['online'] = 'variable-delete -y --exact maintenance_mode';
It is now much easier to switch to maintenance mode.
drush offline # Website offline
drush online # Website online
Example 3: Export the database
The export of the database is a fairly common operation. This export should eliminate unnecessary data tables, including tables cache. The tables it is necessary to clean the data are generally defined according to the site. By default, additional data is stored in cache, watchdog and sessions tables:
$options['structure-tables']['common'] = array(
But this is not all. It is now necessary to add an alias to do an export that excludes data tables listed above:
$options['shell-aliases']['db-dump'] = 'sql-dump --structure-tables-key=common --gzip --result-file=db_dump_' . date('Y-m-d_H-i') . '.sql';
The following command is now available:
Example 4: Complete export
A full export of the site can be done via the command Drush drush archive-dump (drush ard). However, in some situations, a full export is not necessary. In some cases, you may need only the database, as in other just files, etc.. We can therefore set up the following configuration:
$options['structure-tables']['common'] = array(
$options['shell-aliases']['db-dump'] = 'sql-dump --structure-tables-key=common --gzip --result-file=db-dump_' . date('Y-m-d_H-i') . '.sql';
$options['shell-aliases']['files-dump'] = "core-execute tar -czvf files-dump_" . date('Y-m-d_H-i') . ".tar.gz ./";
$options['shell-aliases']['full-dump'] = "!drush db-dump && drush files-dump";
Accordingly, you can make a separate backup of the database, site files or an export of both:
drush full-dump And the most important thing, it is always possible to specify its own options to make custom export.
Example 5: some useful alias
Here are some of the most Drush alias used (from the standard drushrc.php file). See the list of modules (except the Core):
$options['shell-aliases']['noncore'] = 'pm-list --no-core';
Empty the entire site cache:
$options['shell-aliases']['wipe'] = 'cache-clear all';
Disable overlay and dashboard modules:
$options['shell-aliases']['unsuck'] = 'pm-disable -y overlay,dashboard';
Disable all modules that are not part of the Drupal core:
$options['shell-aliases']['dis-all'] = '!drush -y dis $(drush pml --status=enabled --type=module --no-core --pipe)';
Store and send anonymous statistics on the use of Drush by developers. Send these statistics to the team in charge of developing Drush helps to make the software better:
$options['drush_usage_log'] = TRUE;
$options['drush_usage_send'] = TRUE;
Enable Drush debug mode:
$options['v'] = 1;
Set the display level of PHP messages: the default is notice. In the development environment, this value can be set at a higher level, such as warning. In this case, make sure that the value of the option error_reporting is set to E_ALL in the file php.ini on your server configuration.
$options['php-notices'] = 'warning';
Change the encoding of Drush messages:
$options['output_charset'] = 'ISO-8859-1';
$options['output_charset'] = 'KOI8-R//IGNORE';
$options['output_charset'] = 'ISO-8859-1//TRANSLIT';
In the third example, we saw how to remove data from some tables when exporting the database. We can also explicitly list the tables that we want to include in our export:
$options['tables']['common'] = array(
It is also possible to completely ignore a table (data and structure), eg for temporary tables. In case, you must use the option --skip-tables-key=common in your Drush command:
$options['skip-tables']['common'] = array('temp1', 'temp2', 'temp3');
Be notified of the end of the command execution: Drush version 6 introduces a new option, which displays a notification. Useful in the case of a command that takes a little time. This option works on Linux and Mac OSX (on the latter, you must install a utility that interacts with the Notification Center: gem install terminal-notifier). To use this option by default on all commands without having to specify, add the following line to the file drushrc.php:
// Enable notifications by default
$options['notify'] = 1;
The configuration file can contain a lot of useful options, I have listed the most interesting and used. The full list of options can be found in the file drushrc.php.
Photo credits: James Gehrt