Drush is a command line interface that help us to speed up administrative and development tasks for Drupal sites. After installing this Drush, we’ll be able to perform useful action simply by typing command into a terminal —actions that would usually take multiple steps in a web browser. Drush runs on Drupal 6, 7 well as 8.
Note: Drupal 8, works only with Drush 8.
Couple of task which can be be done using Drush easily are :
Download contrib modules
Update Drupal and contrib module versions
Clear the cache
Run Drupal with a lightweight web server
Import, export and merge configuration
Add users and set their roles
Add permissions to roles
Back up and restore Drupal
Copy your database and files to a remote server
Compile twig templates
The first step is to open up a terminal window. Linux & MacOS users should be no stranger to the command line or terminal, but if you use Windows, you might not have used this very much.
The terminal is pre-installed on Linux and MacOS, but you will probably need to install additional software to use Drush if you are using Windows. We would recommend to install “Git Bash” for this. If you havn’t have it already, download and install the Git for Windows package from Google. This is the best terminal available for Windows platform.
Once you have your terminal window open, you will need to become familiar with a few shell commands. If you are new to the command line, try
ls to list the files in the current directory,
cd to change directory, and
pwd to show which directory you are currently in (print working directory).
The command line might feel awkward at first, but as you get used to it, it will really help to speed up your tasks.
Drupal 8 development as it requires Drush 8. Using Composer is far and away the easiest method to install Drush.
First install Composer globally.
$ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer
Now add Composer's directory to your path by editing your .bash_profile
$ export PATH="$HOME/.composer/vendor/bin:$PATH"
Reload your terminal or just re-source the configuration you just added.
$ source ~/.bash_profile
Now that you have Composer working, you can install latest Drush.
$ composer global require drush/drush:dev-master
Keep Drush up to date.
$ composer global update
However, it will install the latest version 8.0.3
Then you can check if the update has been successful by executing:
$ drush --version
Now, let’s begin with Drush. First we'll use Drush to download, install and run Drupal 8:
Step 1: To download latest D8 branch available
drush dl drupal-8 --select
Select the appropriate branch for the development , as i had selected 2 and hit Enter key
To download D7 branch drush dl drupal-7 --select
similar to d8, select branch for the development and hit Enter key.
Once we have done with branch selection we’ll get detailed information about profile and available module on that branch.
Step 2: Next step is to create database. We can use command line for login to mysql and create database
mysql -u root -p
Create database dbname;
Step 3: Now we have created the database, lets install Drupal.
drush si standard --db-url=mysql://[db_user]:[db_pass]@[ip-address]/[db_name]
In this line we are passing standard profile, name of drupal profile to install along with with mysql username , password and newly created database name.
Once we run the above command, we will get prompt with message
“You are about to create a /var/www/html/drupal-8.0.2/sites/default/settings.php file and DROP all tables in your 'd802' database. Do you want to continue?”
where d802 is newly created database name.
Pressing “y” will start drupal installation with standard profile.
Drush generate the random password and display the message -
Installation complete. User name: admin User password: HUoe2kei4o [ok]
Congratulations, you installed Drupal!
Step 4: For security reasons provide 766 / 777 permission to settings.php/files folder respectively.
chmod 755 settings.php chmod 777 files
We completed all the steps to install Drupal using Drush. Now we can see our newly installed Drupal in browser.