Install Drupal With Drush

Drush is awesome. It is sort of the Drupal developer's secret weapon as it can make some things much quicker (and easier) than going through the Drupal UI, plus it can sometimes help with fixing a site that has broken.

Drush also makes it quick and easy to install Drupal. Yes, you could do that through your web browser, but with Drush, you can issue a single command and in a short while, your site is ready.

You will need to have Drupal downloaded and ready to install before you begin. If you are using Lando, you can follow our guide for installing Drupal using Lando. For this guide, I will use the syntax of drush <command>, but if you are running through Lando, you will need to use lando drush <command>.

From the directory where you have downloaded your drupal site, you can simply run:

drush si standard --db-url='mysql://[db_user]:[db_pass]@localhost/[db_name]' --site-name="[Name of Site]"

This will create a database named [db_name] with the credentials of [db_user] and [db_pass] and name the site [Name of Site]. If you are using Lando, you will likely need to change the URL of the database (typically, it should just be database - verify with lando info). If you are wanting to use a site profile other than Standard, replace standard with the machine name of the desired profile. By default the site's user1 (admin) will be 'admin' and the password is a randomly generated string that will be returned on the command line. You can specify the admin username and password using the following flags:

--account-name=[user_name]
--account-pass=[user_password]

So the full command could look something like this:

drush si standard --db-url='mysql://root:root@localhost/websitedb' --site-name="My New Site" --account-name=admin --account-pass=admin

Additionally, if you ever wanted to reinstall the site (which will wipe out all existing data), you can use:

drush si standard --site-name="My New Site" --account-name=admin --account-pass=admin

(You don't need to specify the database when reinstalling.)

Tags