Installing Drupal with Drush
Blog

Installing Drupal with Drush, the Basics

Drush is a command-line interface that helps 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 a 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 tasks which can be done using Drush easily are :
    Download Drupal
    Download contrib modules
    Drush Install Drupal
    Update Drupal and contrib module versions
    Run updatedb
    Clear the cache
    Run cron
    Run Drupal with a lightweight webserver
    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 haven't had it already, download and install the Git for Windows package from Google. This is the best terminal available for the 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.

How to Install:
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 the 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 the latest D8 branch available
               Drush dl drupal-8 --select

Drush Download D8

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.

Drush Download D7

Once we have done with branch selection we’ll get detailed information about the profile and available module on that branch.

Drupal 8 Downloaded

Step 2: Next step is to create a database. We can use the command line for login to MySQL and create the database

mysql -u root -p

Create database dbname;

Drupal 8 Database Creation

Step 3: Now we have created the database, let's install Drupal.

drush si standard --db-url=mysql://[db_user]:[db_pass]@[ip-address]/[db_name]

In this line we are passing a standard profile, name of the drupal profile to install along 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 a newly created database name.

Pressing  “y” will start the drupal installation with the standard profile.
Drush generate the random password and display the message -

Installation complete.  User name: admin  User password: HUoe2kei4o   [ok]                                                  
Congratulations, you installed Drupal!

Drupal 8 Successfully Downloaded with random password

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.

Drupal 8 Home Page

 

Download the Drupal Guide
Enter your email address to receive the guide.
get in touch