A guide to using Drush command line tools.
Drush is a command line shell and Unix scripting interface for Drupal.
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
composer global require drush/drush:dev-master
Add drush executable to your system PATH (~/.bash_profile):
export PATH="$HOME/.composer/vendor/bin:$PATH"
To install a new drupal site, we'll simply create a new directory, grab our make file and run drush make to download the codebase. The make file can pull any version drupal along with any contrib modules we may need:
drush make drush.make.yml
Once we have the codebase we can set up the database using sql-create:
drush sql-create --db-url=mysql://{user}:{pass}@localhost/{database}
and now we can run site-install to complete the installation:
drush site-install standard --account-name=admin --account-pass=admin --db-url=mysql://{user}:{pass}@localhost/{database}
(here's where we'd configure apache virtual hosts to point to our site ...)
We should now be able to access our freshly installed drupal site and login as 'admin'.
Using site aliases we can easily run drush on any drupal installation running on any server.
Copy file 'aliases.drush.php' to ~/.drush directory
$aliases['dev'] = array(
'root' => '/var/www/html/drush-dev',
'uri' => 'drush-dev.local',
);
Now we can target our dev instance from anywhere on the host machine:
drush @dev status
See a list of all available drush site aliases:
drush sa
Now that we have aliases set up, we can sync content and configuration changes between multiple instances.
For example, we can run sql-sync to clone the live database to dev:
drush sql-sync @live @dev
Similarly we can copy any file uploads using the rsync command:
drush rsync @live:%files @dev:%files
Clear all the caches!
# drupal 7
drush cc all
# drupal 8
drush cache-rebuild
Manage contrib modules:
# download
drush dl {module}
#enable
drush en {module}
#disable
drush dis {module}
Update core and all contrib modules:
drush pm-update
Login as another user
drush user-login {username}
Reset admin password
drush upwd admin --password="password"
List all enabled contrib modules:
drush pm-list --pipe --type=module --status=enabled --no-core
Run cron:
drush core-cron
Flush imagecache:
drush image-flush {image-style-id}
View documentation:
drush topic