Chapter 2. Executing Drush Commands

This chapter shows how common site-building and administration tasks in Drupal projects can be performed faster and easier using Drush commands, right after it has been installed. In order to demonstrate this, a sample Drupal project will be installed, configured, extended, archived, restored, and monitored using Drush commands. Get ready to dive into the terminal and start typing rather than clicking!

Downloading and installing Drupal (site-install)

We are about to download the latest Drupal 7 version available, to be the foundation of our test project. Let's call it Festival: a site to promote our favorite music festival.

Note

Almost everything in the rest of the chapter is compatible with Drupal 6. Whenever there is a difference, it will be pointed out.

The first thing we need to do is to download Drupal core into a directory which will be our root path. Here is an example of how to achieve it:

$ cd /home/juampy/projects
$ drush pm-download --drupal-project-rename=festival drupal
Project drupal (7.10) downloaded to [success] /home/juampy/projects/festival.
Project drupal contains: [success]
- 3 profiles: minimal, standard, testing
- 4 themes: seven, stark, garland, bartik
- 47 modules: simpletest, shortcut, text, list, number, field_sql_storage, options, field, forum, node, help, contact, php, book, aggregator, dashboard, toolbar, syslog, taxonomy, user, filter, rdf, dblog, menu, path, translation, comment, field_ui, color, trigger, locale, openid, statistics, search, contextual, blog, block, poll, update, file, overlay, image, profile, system, tracker, drupal_system_listing_incompatible_test, drupal_system_listing_compatible_test

The pm-download command outputs a description of what version it has downloaded and its contents. We have used the --drupal-project-rename option to rename the generated directory from drupal-7.10 to festival.

Now, we are going invoke the Drupal installation process. Without even opening the browser and just by typing one Drush command we will obtain:

  • A database called festival with the basic data for our site defined by an installation profile called standard
  • The sites/all/settings.php file configured and pointing to a database
  • The sites/all/files directory ready to be used by the website

First we will execute it, and then we will go through its syntax and output in detail. Note that you have to replace the username and password strings in the command with an existing MySql's username and password (normally, this is the root user for local development environments):

$ drush site-install  --db-url=mysql://username:password@localhost/festival  --site-name=Festival  standard
You are about to DROP your festival database and then CREATE a new one. Do you want to continue? (y/n):

Unless you already have a database with the name festival, you can safely accept the warning. This will start the installation process:

Starting Drupal installation. This takes a few seconds ... [ok]

This command installs a Drupal site in our system. We provided with it the following arguments and options:

  • A MySQL database connection string that the command will forward to the installation process in order to create and configure the database.
  • The site name (Festival). If not given, our site would be called "Drupal".
  • An installation profile name. Drupal core comes with three installation profiles: Minimal, Standard, and Testing. We have chosen the Standard installation profile as it configures the most common features of a Drupal site. Custom or contributed installation profiles can be placed in the profiles directory to be used instead.

Once the process completes, we only need to configure our web server so a local URL (for example, http://festival.localhost) that resolves to the root directory of our project (which is /home/juampy/projects/festival for this example). It is outside of the scope of this book to instruct you how to do it, but, in case you need it, you can find a lot of useful information at http://drupal.org/node/157602. Once you have set it up, open your web browser, type http://festival.localhost in the URL address field and hit Enter. Here is an example of how our website looks like when opening it for the first time:

Downloading and installing Drupal (site-install)

The site's homepage is presented. You can log in as the administrator by typing admin in both the Username and Password fields at the User login form.

site-install has plenty of options available. Here are some command examples and a description of what their output would be:

  • Download the Spanish Drupal core translation, install Drupal with Spanish as the default language and Spain as the default country using sites/drupal.localhost instead of sites/default for the site configuration:
$ wget -O profiles/standard/translations/drupal-7.10.es.po  http://ftp.drupal.org/files/translations/7.x/drupal/drupal-7.10.es.po
$ drush site-install  --db-url=mysql://username:password@localhost/drupal  --site-name="Spanish Festival"  --locale=es  --sites-subdir=drupal.localhost standard  install_configure_form.site_default_country=ES

  • Provide specific details for the admin account:
$ drush site-install  --db-url=mysql://username:password@localhost/drupal  --account-name="Webmaster" --account-pass="W3bm4st3Drpl"  --account-mail="[email protected]" standard

  • Specify a MySQL account with higher privileges to create the database (for example, the MySQL root user account):
$ drush site-install 
--db-url=mysql://username:pass@localhost/drupal 
--db-su=root --db-su-pw=rootPassword standard

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.55.14