navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Simplified Drupal Sites with Drush

Simplified Drupal Sites with Drush

with Jon Peck

 


Manage your Drupal sites even more efficiently with Drush, the shell interface for managing and scripting Drupal site development. In this quick course, author Jon Peck describes what Drush is, how to install it, and how to use it effectively for everyday—and exceptional—tasks.

The course describes how to manage users, download and install modules and themes, archive and restore your entire site, and employ site variables for fast, full control over your Drupal sites. Plus, discover how to script an entire Drupal site installation with and without site profiles.
Topics include:
  • What is Drush?
  • Installing the prerequisite files
  • Installing Drush with PEAR, manually, and just for Windows
  • Installing Drupal sites
  • Managing themes
  • Controlling user access
  • Controlling cache and cron
  • Reading logs
  • Updating modules

show more

author
Jon Peck
subject
Developer, Web, CMS, Web Development
software
Drupal , Drush
level
Intermediate
duration
1h 22m
released
Dec 06, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00(music playing)
00:03Hi! I am Jon Peck and welcome to Simplified Drupal Sites with Drush.
00:09I am a Zend-certified PHP engineer with more than a decade of web application
00:13development experience.
00:15In this course we'll look at Drush, the command-line utility for managing Drupal sites.
00:21I'll start by describing exactly what Drush is and why it can be helpful, then
00:25show you how to install it and perform core functions including module, user,
00:30and cache management,
00:32plus other techniques useful for quickly assembling and manipulating a
00:35functional Druple site from the ground up.
00:38Let's get started with Simplified Drupal Sites with Drush.
Collapse this transcript
Using the exercise files
00:00In this course, I'll be creating a Drupal 7 site from the ground up using the
00:04Drush command-line utility.
00:06Drush typically resides in the same web hosting environment as the sites it manages.
00:11The recommended configuration for the host environment is PHP 5.3 or above,
00:17Apache 2 or above and MySQL 5 or above.
00:21Other web servers such as Nginx or IIS and other databases like PostgreSQL
00:26should function but will not be supported.
00:29Setting up an AMP stack is beyond the scope of this course.
00:32If you do not already have a development server I recommend using a local
00:36development server running on your workstation.
00:38The Up and Running with Linux for PHP Developers course here in the lynda.com
00:43Online Training Library will allow you to have an optimized virtual server
00:47running like any other program in your existing operating system.
00:51Additionally, an overview of how to interact with the Linux command-line is
00:55provided with many principles that also apply to Mac OS as well.
00:59I will be demonstrating using a server created using this technique.
01:03Alternatively, you can use a web server solution stack package in your
01:07native operating system.
01:08XAMPP from apachefriends.org has distributions for Linux, Windows, Mac OS X, and Solaris.
01:15WampServer from wampserver.com is explicitly for Windows and MAMP from mamp.info
01:23is for Mac OS X only.
01:25Each of these packages will allow you to execute the exercises found in this course.
01:30Installing additional software within your native operating system is covered in
01:34the course installing Apache, MySQL, and PHP with David Gassner here in the
01:39lynda.com Online Training Library.
01:42If local development is not an option, remote and third-party hosted servers
01:46that have the appropriate versions of PHP, MySQL, and Apache also support Drupal 7.
01:52SSH access to a command-line shell is required to be able to use Drush.
01:56So verify that the third- party provide shell access.
02:00You will need access to the command-line in the location of the Drupal site installation.
02:04For Mac and Linux the terminal allows you to access the command-line which
02:08includes access to the SSH command if the site is hosted remotely.
02:13In Windows the Command prompt will work with Drush, but does not provide SSH access.
02:19You can use the free program PuTTY to connect via SSH to remote servers
02:23available from the official PuTTY website.
02:26The exercise files for this course are contained in a folder named "sandbox"
02:30that my virtualized Linux server can access.
02:33Depending on your web server configuration, you may need to store these files in
02:37a different place such as a remote web server or in a folder accessible by a
02:41local Apache, MySQL and PHP stack.
02:44In addition to these files, a quick reference to the Drush commands covered in
02:49this course is provided as a PDF.
02:51Feel free to print out and distribute this quick reference.
02:54A final note, as different web hosts and configuration serve content from
02:59different URLs, the address you see in my browser may not exactly match what you
03:04see on your workstation.
03:06Additionally, the location shown in the command prompt demonstrations will
03:09differ depending on the location of site files.
03:12The commands will still apply in the same way.
Collapse this transcript
What you should know
00:00This course is designed with the assumption that you have the foundational
00:03knowledge of Drupal 7 installation and management, including modules and themes,
00:08user management and so forth.
00:11Drupal 7 Essential Training by Tom Geller here in the lynda.com Online
00:15Training Library demonstrates how to download and install Drupal, add content
00:20and graphics to a site, change layout and design elements, control visitor
00:24interactions, and expand the site's capabilities beyond what's available in Drupal's core.
00:30Drush is designed for use on a server running a UNIX like OS such as Linux or Mac OS.
00:35So you should have some base knowledge of working with a command-line shell
00:39interface such as Linux or Mac terminal.
00:43If you aren't familiar with Linux or the Mac terminal, I recommend the Up
00:47and Running with Linux for PHP Developers course here in the lynda.com
00:51online Training Library.
00:53It includes some thorough descriptions and demonstrations of how to work with
00:56the Linux command-line, which is very similar on the Mac.
01:00If you require Windows for your development in server environment Drush does
01:04support most functionality on Windows and provides a dedicated installer that
01:08often lags in both functionality and timeliness.
01:12As the implementation is incomplete and has known issues only the installation
01:16procedure for Drush for Windows will be covered for completeness and will not be supported.
01:22Finally, this course covers a large number of everyday commands contained with
01:26Drush, but is not a comprehensive survey of every single command available.
01:31Additionally, depending on the version of Drush that you are using some commands
01:35may have evolved slightly.
01:37This course was written using Drush 5 .8 and is intended to be compatible
01:42with future versions.
01:44If any inconsistencies arise using a newer version check the documentation
01:48and change logs.
Collapse this transcript
1. Getting Started with Drush
What is Drush and why should I use it?
00:00Before describing what Drush is, I am going to take a step back and outline what Drupal is.
00:05From a high-level perspective, Drupal is an open-source content management
00:10framework that can be used to build a content management system.
00:13By providing a highly modularized architecture, the building blocks and the base
00:17framework can have functionality added through modules and designs in themes.
00:23Drupal is used to power websites of many different scales from simple static
00:28portfolios and brochures to interactive blogs, and enterprise grade web
00:33applications and corporate sites.
00:36The management of these sites and features is done almost exclusively through an
00:40administrative web interface.
00:42By providing an interface without requiring the use of a client other than a web
00:46browser virtually anyone can build and maintain a site.
00:50This versatility comes at a price.
00:53By providing an exclusive web interface Drupal site administrators are met with
00:57a number of frustrating limitations.
01:00Each page load consists of multiple transactions.
01:04The browser makes a request, the server generates a response, and the browser
01:08interprets the response.
01:10This is a number of steps.
01:12Markup is also transferred along with CSS and JavaScript, so on and so forth.
01:17Building a page on the server takes resources and time, depending on the number
01:22of modules that are enabled, a single page request can take over 128 megs of RAM
01:27and generate dozens of database queries.
01:29An additional overhead is introduced by providing a menu and form genuine user interface.
01:35Options can be buried in a maze of menu items.
01:39To clear the cache for example, I'll have to log into the site, click on
01:45Configuration, click on Performance, then click Clear all caches.
01:54From start to finish, this manual process took a lot of work.
01:58Given that these interfaces are web- based, scripting actions is impractical
02:03due to the number of HTML elements in responses that need to be parsed and interacted with.
02:08Yes, testing framework such as Selenium provide a mechanism to script
02:12activities, but in this context it's like wanting a cup of tea and flying to
02:16India, instead of just putting the kettle on.
02:19Finally, web interfaces restrict access to potentially damaging activities.
02:24I hesitate calling this a limitation as there's hundreds of fantastically good
02:28reasons for preventing someone who has just enough knowledge to do damage
02:31from wreaking havoc.
02:33With that said, sometimes it's good to pop the hood if you know what needs to be done.
02:38With that context, I can describe what Drush is.
02:41Starting with the name, Drush, stands for Drupal shell.
02:45A shell is a software that provides an interface to a particular component,
02:50typically an operating system.
02:52Shells can be command-line and graphical.
02:54Drush is a command-line shell.
02:56In particular, Drush can be used as a scripting interface, allowing groups of
03:01actions to be performed with a single command.
03:04Drush has two official pages.
03:06A website drush.org, which primarily consists of generated documentation any
03:11project page on drupal.org.
03:14Drush has been around since 2006 when it was initially developed by Arto
03:19Bendiken to manage Drupal 4.7 sites.
03:22A partial redesign and reimplementation for Drupal 5 in 2007 increased
03:27visibility of the project, which has since evolved into a full Drupal.org
03:31project maintained and expanded by the community.
03:35Today Drush supports Drupal 6, 7 and 8, and works on Linux, Mac OS, and
03:41Windows Operating Systems.
03:43Why use the command-line tool like Drush when functionality is available
03:47elsewhere in the Graphical User Interface?
03:50Most simply, Drush will save time with sheer speed and versatility.
03:54For example, clearing the cache can be done with one simple command instead of
03:59navigating through multiple menus and interfaces.
04:02Using the scriptable capabilities operations such as downloading and installing
04:06modules can be automated and placed in version control.
04:10Providing the tools that interact with Drupal from the ground up, the overhead
04:14of browser transactions is eliminated and precise actions can be performed with
04:18less chance of missing a checkbox or option.
04:21Drush is a fantastic tool that I use on a daily basis, but it has some drawbacks
04:26in terms of approachability.
04:28The documentation for Drush, while thorough and improving, can be intimidating and
04:33obtuse for people who don't live, breathe, and code a Drupal.
04:37Drush.org the homepage is an example of this.
04:41It's a very useful source for information, but it's literally dozens of commands
04:45and all of their arguments are displayed on one page. Where to start?
04:48My goal is to educate and inform about how Drush can be practically leveraged to
04:53administer Drupal sites.
04:55To do that, I will be building a fully functional Drupal site from the ground up.
05:00This includes module installation and administration, user and cache management
05:04for troubleshooting and maintenance, to copying entire sites.
05:08I will be performing all demonstrations in this course using Drush 5.8.
05:14If you look at the Drupal.org homepage, you will see the version displayed as 7.x-5.8.
05:21This is due to the way drupal.org versions files.
05:25Drush 5.8 is compatible with both Drupal 7 and Drupal 6.
05:30In this course, I will demonstrate using Drupal 7.
05:33The tools and techniques described in this course are common core functionality
05:37that should be safely future proof.
05:39In the next segments I will demonstrate how to install Drush.
05:43The README.TXT included with Drush provides installation instructions as well.
05:48Refer to them for additional guidance if needed. I'll be upfront.
05:52Installing Drush can sometimes be complicated and using Drush is actually
05:56easier than installing it.
05:58With that said, most of the time installation is easy and straightforward.
06:03I will demonstrate multiple techniques that will cover the vast majority of
06:06system setups and installation options.
06:09Not all steps are necessary for every system.
06:12Use your best judgment to determine which combination is best for your needs.
Collapse this transcript
Installing the prerequisites wget and unzip
00:00This section installing the prerequisites is intended for Linux and Mac users.
00:05Windows users do not need to do this and should skip to the Windows
00:09installation segment.
00:11Before I start installation the first step I need to take is to ensure that the
00:15prerequisites are installed. Drush leverages a new Wget, a free and open source
00:22software package, for retrieving files.
00:24And Unzip, a mechanism for extracting archives.
00:28Without them Drush just won't work properly, so these prerequisites need to be installed.
00:33Most hosting environments and operating systems will already have both
00:36these commands installed.
00:39Open a terminal and connect to your development environment.
00:42I'll first demonstrate on my Linux virtual server, verify that Unzip is installed.
00:49To verify, type the following: unzip.
00:53If you do not see help listing then Unzip needs to be installed.
00:56If the command line environment is Linux then Unzip can be installed using
01:00the package manager.
01:01For example, with Ubuntu and Debian systems use the command "sudo apt-get
01:08 install unzip".
01:13On CentOS and other systems using the yum package manager use the command
01:18"sudo yum install unzip".
01:22When complete verify that Unzip is installed.
01:29Next, determine whether or not Wget is installed.
01:32To do that just type "wget", if it is installed a simple error stating that no URL
01:39was given will be shown.
01:40If this error from the Wget is shown then no further work is required and you
01:44can skip to the next segment.
01:46If Wget is not installed then it'll need to be installed before Drush can be used.
01:51If the environments that will be used for Drush is a third party shared host
01:55that does not provide you privileges to install programs, please contact the
01:59host and request that Wget be made available.
02:02Similar to Unzip, Wget can be installed using the package manager on Linux systems.
02:08Ubuntu and Debian systems can use the command "sudo apt-get install wget".
02:16On CentOS and the other systems using the yum package manager use the command
02:20"sudo yum install wget".
02:27Then verify that the Wget has been installed by typing "wget";
02:31I'm going to exit out here and clear.
02:37If you are using Mac OS X Lion or Mountain Lion there is a strong possibility
02:41that you do not have Wget installed.
02:44To do so it'll need to be compiled and installed as there is no officially
02:49recommended binary available.
02:51This will take some additional steps, but I'll demonstrate them.
02:55To install Wget it must be compiled which on a Mac requires either Xcode 4 or
03:00Xcode 4 command-line tools to be installed.
03:04If you already have Xcode 4 installed, you do not need to explicitly install
03:08the command-line tools.
03:10If you don't have Xcode 4 installed visit developer.apple.com/downloads
03:16and download the current version of the command-line tools for Xcode 4
03:19your operating system.
03:21Once these tools are installed installation can continue.
03:25First, I will download Wget directly from the home page using the cURL
03:29command-line utility which comes installed with Mac OS X. From the command-line
03:33enter the following command: curl Space -O
03:37http://ftp.gnu.org/gnu/wget/wget-1.14.tar.gz.
03:58Next, decompressed the downloaded files using the tar archive utility, "tar Space
04:03-xzf", then the name of the file; change directory to the decompressed files.
04:13Before compilation a configuration step is needed, only one option is required
04:18specifying that SSL support will be handled with open SSL, meaning files can be
04:23downloaded from secure sites.
04:25So type: ./configure --with-ssl=openssl.
04:36Once the configuration is complete build the source by typing "make".
04:45This will take a minute or two.
04:47When compilation is been completed install the file into the default location
04:52user local bin, so type "sudo make install", it will ask me for my password.
05:01Following installation, verify that the Wget is installed, wget.
05:06Now that the-based dependencies of Drush have been fulfilled I can install
05:10Drush itself.
Collapse this transcript
Installing Drush with PEAR
00:00The preferred method for installing and maintaining the Drush utility is to use PEAR.
00:05PEAR is an acronym that stands for the PHP Extension and Application Repository,
00:10which provides a library of open source PHP code including a code distribution
00:15and package maintenance system.
00:17This method is preferred as it's relatively OS agnostic and makes it easy to
00:21stay up-to-date and manage dependencies.
00:24PEAR is not required to use Drush, if you prefer to manage software installation
00:29more directly use the manual installation instructions in the next segment.
00:33While there are a number of steps required it is a one-time setup.
00:38I'm going to open a terminal and connect my sandbox environment.
00:44
00:44To determine whether or not PEAR is installed type the following command "pear version".
00:50If PEAR is installed the version will be displayed, if the version is not
00:54displayed then PEAR needs to be installed.
00:57More in-depth instructions are available at pear.php.net.
01:01I will demonstrate the most common techniques.
01:04If you are using a Linux distribution such as Ubuntu or Debian the apt package
01:09installer can be used to install PEAR, "sudo apt-get install php-pear".
01:17It'll ask me for my password, I say I wish to continue and it installs.
01:26If you are using a Linux distribution such as CentOS, type the following command
01:31"sudo yum install php-pear".
01:36If you would like to install PEAR on any other system including MacOS X without
01:40using a package manager, type the following: cd Space user/local, sudo wget
01:48http://pear.php.net/go-pear.phar then pseudo php -d detect_unicode=0, and then,
02:05go-pear.phar, everything is correct, press Enter to continue and Enter again and
02:14then verify the PEAR is installed by typing "pear Space version".
02:20If you're using a third-party host that does not provide PEAR there is a web
02:23front-end mechanism that can be used to install PEAR, this method is a bit more
02:27involved that can provide an installation mechanism in some circumstances.
02:32Due to the variations between third- party hosts the PEAR web installer will not
02:36be covered in this course.
02:38With that said documentation is available on
02:40pear.php.net/manual/en/installation.getting.php.
02:48Before installing Drush ensure that PEAR is updated, depending on your
02:53environment you may not need the sudo command at the beginning of the line.
02:56If you get error stating that you do not have permission, login as root or use
03:00the sudo command: sudo pear upgrade Space --force pear.
03:13Drush has PEAR specific dependencies that need to be installed, type "sudo pear
03:19upgrade Space --force Console_ Getopt and then Console_Table".
03:32Finally, make sure everything else is up-to-date "sudo pear upgrade-all".
03:39Now that the groundwork is set Drush can be installed.
03:43First, specify the location of the Drush installation files, "sudo pear
03:48channel-discover pear.drush.org".
03:55Finally, install Drush itself "sudo pear install drush/drush", verify that Drush
04:05is installed by using the "which" command, "which" locates a command. Use "which" to
04:09locate Drush, "which drush" then attempt to execute Drush, "drush".
04:17If you see a message like Drush needs to download a library from etcetera,
04:22you're seeing a non-permissions issue, to resolve: "execute sudo drush", and the
04:29error message will go away.
04:30Type the following to remove the administratively created directory: sudo rm -Rf
04:40~/.drush, then verify that Drush is properly installed, "drush".
04:46Now that Drush is installed via PEAR it can be upgraded with both the PEAR
04:50"upgrade all" command demonstrated earlier and the command specific to upgrading
04:54Drush, "sudo pear upgrade drush".
05:00Drush will inform you when an upgrade is available during normal usage with
05:03a simple notice to the command-line which won't affect the operation you're performing.
05:07Drush and all its dependencies have been installed. Now what?
05:12In the next chapter, I will demonstrate how to install a site using Drush, how
05:15to get information about the site and the modules, and how to manage modules,
05:19users, and more.
Collapse this transcript
Installing Drush manually
00:00Depending on the available permissions and comfort level a manual installation
00:04may be the most appropriate.
00:06At the highest level, Drush manual installation is just unzipping the archive.
00:10However, there are couple steps involved in making it useful which I will demonstrate.
00:14First, download Drush using Wget.
00:16Wget in its simplest operation just takes URL which it will download to the
00:22current directory, type "wget" then URL of Drush 5.8,
00:27http/ftp.drupal.org/files/ projects/drush-7.x-5.8.zip.
00:41Now that the archive has downloaded, extract it using the Unzip command, "unzip drush".
00:48Now that the contents have been extracted, I no longer need the archive, so I'll
00:52remove it to keep my home directory clean.
00:57The zip file contains a single directory named Drush, change directory to the
01:01Drush directory "cd drush".
01:05Next, I'm going to use the chmod command to grant myself execution permissions
01:09on the Drush executable, chmod u stands for user, plus (+) means to add, and x
01:16stands for execution followed by the name of the command, "drush".
01:21Drush can now run, but if I was in any other directory then I would have to know
01:25the full path to be able to execute it, which is frankly a pain.
01:29Instead, I'm going to make the commands available no matter which directory I'm in.
01:34To do that, I first need to know exactly what directory I'm in right now, so I
01:38will use the pwd command which returns the working directory.
01:42I'm currently in users John Peck Drush;
01:45your directory will be different depending on the operating system and user.
01:49If you have administrative privileges, you can perform the following command to
01:53symbolically link Drush to the user bin directory which will make the command
01:57available throughout the entire system.
01:59As the directory is protected, elevated privileges are required, so either use
02:03sudo or log in as root for the step, I'll be using "sudo" followed by "ln" for
02:08link "-s" for symbolic.
02:11Next, I'll provide the path to be linked to, which is the directory shown
02:14with the pwd command: /Users/johnpeck/ drush followed by slash (/), and then
02:22"drush", the command itself.
02:24Finally, Space then the path for the symbolic link, which I will put in user/bin/drush.
02:32Change directory back to the home directory and test that the link worked "which drush".
02:37The result should show that the Drush command is available at user/bin/drush.
02:43If you do not have administrative privileges then there is another method that can be used.
02:48By editing the shell configuration file, I can manually specify the location of Drush.
02:53Depending on the system that is being installed the file may be slightly
02:57different. It's highly likely that you have one of the following files already
03:00installed: bash_profile which is what's available on Mac, bashrc which is the
03:07default on Ubuntu and Debian, and . profile which is another possibility.
03:12To check for the files, use the list directory contents command ls and I'll look
03:18for a: ~/.bash_profile, it's not there; let's try ls ~/.bashrc, it's also not
03:29there; and then profile, also not there.
03:34If none of these files exist, you will need to create one.
03:37So start with .bashrc first, on a Linux system, and bashprofile on a Mac. I'm
03:42going to edit the file and I'm going to use the text editor, nano.
03:46So, "nano Space -w", currently I'm on the Mac, so "~/.bash_profile", add the following
03:57line to the end of your file.
03:59I am going to use the directory shown with PWD command, this will be different
04:03for your system: export PATH="$PATH:/ Users/johnpeck/drush" exit and save by
04:17pressing Ctrl+X then Y to confirm.
04:19Load the configuration file using the source Command, "source", I'm going to load
04:25bash profile, so you may need to load bashrc or profile depending on the system.
04:31The next time I log in, the configuration will be loaded, so this is a one-time
04:36thing: ~/.bash_profile.
04:40Verify the Drush is available by using the "which" command to locate Drush, "which drush".
04:47Drush has now been manually installed.
04:50To upgrade Drush, you'll need to remove the Drush directory and repeat the
04:54extraction, and make the Drush command executable as previously demonstrated.
04:59In the next chapter, I will demonstrate how to install a site using Drush, how
05:03to get information about the site and the modules, how to manage modules, users
05:08and more.
Collapse this transcript
Installing Drush for Windows
00:00An official installer for Drush is available for Microsoft Windows, providing a
00:04convenient method for installing Drush and its needed components.
00:09The homepage is at: drush.org/drush_ windows_installer, and it provides current
00:18project status, links to the files, and installation instructions.
00:23The Windows installer usually lags a bit behind the officials Drush release,
00:27illustrated by the rest of the course using Drush 5.8 and the Windows
00:31installer still on 5.7.
00:33The Drush installer supports Windows 7, Windows Vista Service Pack 2 or higher,
00:38Windows XP Service Pack 3 or higher, Windows Server 2003 Service Pack 2 or
00:44higher, Windows Server 2008, and Windows Server 2008 R2.
00:50There are also a couple of supported shells, minsw and msysgit which are
00:55recommended, the command prompt, and PowerShell.
00:59Msysgit is not distributed with the full Drush installer as it's a separate project.
01:04However, it does provide Git in patch support.
01:07The full installer for official Git is recommended but Shell installation is not
01:12covered in this course.
01:13There are some limitations.
01:15Most SQL commands will work with SQL Server but the dump database command will not work.
01:21SQL-sync is not really working, and Drush make does not work correctly in 5.7.
01:28To use the Windows installer, download the installer then run it with the user
01:31account that has administrator privileges.
01:38Click Next on the Welcome page, you will be given a number of options.
01:42The first three items are required runtimes, leave them alone.
01:46The fourth, add support for the Rsync command if you're interacting with
01:50Linux and UNIX servers.
01:52Register Environment Variables is a useful shortcut that will automatically add
01:55all required paths to the Path Environment Variable. The last option,
02:02Configure Windows Remote Management, allows remote commands to be used from the client.
02:06Where Drush is installed to a remote Windows server where Drupal is hosted.
02:11For more in-depth details on these options refer to the installation guide
02:14linked from the bottom of the Windows installer homepage.
02:18When I'm done configuring the options, click Next and then Install.
02:23If prompted, say yes to run as administrator, then click Finish.
02:30Verify that Drush is installed by double -clicking on the Drush command's prompt
02:34and typing the following, "drush".
02:38In the next chapter, I will demonstrate how to install a site using Drush, how
02:43to get information about the site and the modules, and how to manage modules,
02:47users, and more.
Collapse this transcript
2. Core Functionality for Everyday Operations
Site installation and introspection
00:00Throughout this course I will be building a Drupal site piece by piece.
00:04In this segment I will start by downloading the Drupal core, gathering
00:08information about site status then performing a site installation.
00:12Throughout this process I'll describe how each command works, and how it relates
00:16to everyday operations.
00:19Before you begin identify the location of your Web server root that you want to
00:23build your site and determine the following about the database, the username
00:27and password, database name, and the port that you wish to use for connection settings.
00:34I'll start by opening a command line, connecting to my sandbox, and
00:41navigating to the Web server root where I will start the base installation,
00:45cd /media/sf_sandbox.
00:48I'll list the content to the directory to ensure that there are no files on it, ls - la.
00:55If you type drush help, you will see a comprehensive list of all commands
01:00that drush is aware of.
01:02To get help on any command type 'drush help' then the name of the command.
01:07The first command I will demonstrate is pm-download, which stands for
01:12Project Manager download.
01:17Project Manager is a group of commands within Drush that allows you to download,
01:20manipulate, and analyze the Drupal extensions both modules and themes.
01:25While I can type the entire command there is a shorthand alias, dl;
01:29that I will use to save time.
01:31Drush will display high-level information about the command, followed by
01:35examples, arguments, options, and finally any aliases.
01:46The first of the examples is the commands that I will be using, downloading the
01:49latest recommended release of Drupal core.
01:52The only argument that the Project Manager Download command takes is a comma
01:56separated list of projects to download, which in this case is the Drupal core
02:00itself, drush dl and then the project name drupal.
02:05As there is no site installed Drush will just default to downloading Drupal and
02:09extracting the contents into a directory named Drupal 7.17 which is as of this
02:15writing the current version.
02:16Once Drupal core is downloaded Drush will be aware of the context, and will not
02:20append to the project version to any downloaded modules or themes.
02:24I see a success message describing what happened, followed by a summary of
02:28everything that was in the downloaded project.
02:30In this case 3 profiles, 4 themes, and 47 modules.
02:36I can also manually specify a particular release by version using drush dl
02:40Drupal 7.x, which will download the latest version of Drupal 7 now 7.15;
02:48we'll expressively download Drupal 7.15.
02:54Perform a directory listing to see what changes were made.
02:56There is one directory Drupal 7.17 as described in the status message.
03:03Drush keeps all the temporary files and results of its operations out of the
03:07site root, which helps keep the workplace clean.
03:09Change directory to Drupal 7.17 then list the directory contents.
03:15All of the contents that Drupal project have been extracted which is
03:18exactly what I wanted.
03:19Let's get some introspection into Drupal, the command core status aliased as
03:24just status, so 'drush help status' provides a bird's eye view of the current
03:30Drupal installation.
03:31I'll show the help on the core status command.
03:35There not nearly as many options for this Command, but it doesn't mean that it is not helpful.
03:39For now I just want to get the status report, drush status.
03:44The Drupal version Default and Administrative theme, PHP configuration, Drush
03:49version and configuration, and Drupal root are displayed.
03:53This is incredibly helpful for giving context when asked to help out with another site.
03:58When a Drupal site is installed this site will give connection information as well.
04:03The next command I will demonstrate is site-install aliased as si, drush help si.
04:11Site Install is a powerful tool allowing an administrator to complete the
04:15install a site using a given installation profile with a single command, rather
04:19than slogging through pages of configurations.
04:22It also creates the first user UID1 and randomly generates a password for the
04:26user displaying the result.
04:28There are also a large number of options for the site-install command.
04:33In its simplest form site-install will use the database configuration that was
04:36specified in settings.php, but as this is as freshly downloaded installation
04:41that information is missing.
04:43So if I just do drush si, Drush rightfully complaints that there is no database
04:49connection so I will need to specify it using drush si --db-url=.
04:58This is only required for the initial install not reinstalls.
05:02The DB URL is specified using the Drupal 6 database URL for conciseness and will
05:07generate the regular array structure automatically.
05:10I'm using a MySQL database connection with a username and password root.
05:15I'm going to put it on the localhost at 127.0.0.1, on port 3306.
05:26That's the default port using the database Drush.
05:30Your connection settings may be slightly different than the ones I'm using,
05:34please adjust them to reflect your working environment.
05:37Before I perform the command I'm going to specify one more option the
05:42password of the admin user, so I don't have to keep track of the randomly
05:46generated password.
05:47This is fine for a development environment but avoid doing this in a
05:49production context.
05:51--account-pass=admin, press Enter and Drush will install the site, but first it
06:01will prompt to you about what it's about to do.
06:03Create the database tables which include dumping any existing database tables.
06:08So it wants to be sure that this is what should be performed.
06:11I am sure so I'll just say y for yes.
06:13A few moments later an installation is complete and the admin password is
06:18displayed for my records.
06:21I'll switch to my browser and navigate to where my site is installed which in my
06:25case is http://sandbox.dev:8080/ drupal-7.17, Welcome to Site-Install.
06:37This site has been installed using the standard Drupal installation profile.
06:42Login using the username and password, admin, admin, to verify everything
06:48is working properly.
06:49Switch back to the terminal.
06:52Now that the site is installed drush status is going to be a lot more helpful.
06:58In addition to the status information shown before the site URL database
07:03connection information, ability for Drupal to bootstrap, site and file paths are displayed.
07:09Now that the site has been installed and I have some perspective into the site
07:13I'm going to start managing the modules including listing, searching, enabling,
07:17and disabling modules.
Collapse this transcript
Listing and managing modules
00:00The Start Drupal interface for module administration works but doesn't scale
00:04well when dealing with large numbers of modules and doesn't allow filtering
00:08without a third-party module.
00:10Additionally, it won't allow downloading of new modules which I've demonstrated
00:14in the previous segment.
00:16Drush can also provide a fire hose of information.
00:19I'll demonstrate how to control that firehouse.
00:22The command, Project Manager List, aliased as PML shows the list of available
00:27modules and themes, "drush help pml".
00:32To be clear this list is what is available in the Drupal installation, not
00:36what's available to download on drupal.org.
00:39I'll start by listing every single available extension, "drush pml".
00:45A fantastic amount of information, the package, name, type, status, and version are shown.
00:53Let's filter this down a bit and only show Enabled extension.
00:57The option, Status, takes a comma separated list of options including an; Enabled,
01:02Disabled, and Not Installed.
01:04I will start with: drush pml status = " not installed", as this requires quotes.
01:16The list can also be changed using a comma, to demonstrate this I will show
01:20every module that is not installed and/or disabled.
01:23So, status = "not installed, disabled".
01:32Another useful argument is type which filters by extension type.
01:39There are two options, Module and Theme, I'll list only themes, type=theme.
01:47The four core themes are now shown.
01:49I will get into theme management in the next segment as it's similar to module
01:53management but has enough quirks to set it apart.
01:56The next argument I will demonstrate is filtering by package.
02:00Before I do that, I'm going to download the develop project, so there will be
02:04some variety, "drush dl devel".
02:08The develop projects also provides Drush commands if enabled.
02:11In fact, many Drupal projects provide Drush support.
02:15Now that devel has been downloaded, list all extensions again, drush pml.
02:22I can see that devel is in package development.
02:25I'd like to only show extensions in the development package.
02:29So I will use "drush pml" with the option package=development, which also takes a
02:36comma separated list of package names, case insensitive.
02:41The modules in the devel package are now shown.
02:44I just downloaded a new extension devel.
02:47But what information can drush tell me about the devel module itself?
02:51Two commands are available, the first, Project Manage Info aliased as PMI, "drush
02:58pmi devel" can give me some technical information about the module.
03:04A second command, Product Manage Release notes, aliased as RLN, "drush rln",
03:10will show release notes on a particular package.
03:16Use arrow keys to scroll, press Space to go down a page and then press Q to quit.
03:23What if I want to search for a particular package, but I don't know exactly what
03:26package it's in? Drush doesn't support this functionality explicitly.
03:31But I will show you a trick that's available on UNIX like systems.
03:35By piping the output of the package manager list dgrep, I can search using a keyword.
03:40Let's say I want to determine whether or not the comment module is enabled.
03:43I will start with "drush pml" to get the list, then the pipe character, to send the
03:50output of PML to another command.
03:51I will use grep which will filter based on a regular expression which can also
03:56be just the word I'm looking for.
03:58I will use "Space -i" to make the search case insensitive.
04:03I am looking for comment, so I will just type the word "comment".
04:08I can see that there is one module named "comment";
04:12by combining the list command with grep I can quickly filter the list of modules.
04:17It looks like the comment module is enabled.
04:19I don't want anyone commenting on my development site.
04:23So I will just disable it using the Project manager disable command, which can
04:27also be shortened to just dis, drush help dis.
04:31The Disable command will disable an extension and any dependent extensions if any.
04:37So, "drush dis" and then "comment".
04:41I'm prompted if I want to disable comment.
04:44While I'm sure I want to, I just want to say yes to any prompt that's given to me by Drush.
04:50I'll say no for now.
04:51Then redo the command, drush dis comment.
04:55But this time with an additional option, -y.
04:58Which will say yes to any prompt.
05:02Same as using the web interface disabling the module isn't the same as
05:05completely uninstalling it.
05:07Drush supports this as well with the Project Manager Uninstall command,
05:11drush help pm-uninstall.
05:15Notice that there's no alias for this command, pm-uninstall takes a list of
05:20modules to be uninstalled.
05:21I will uninstall the comment module and I will use the same yes option right at
05:26the front to show that it doesn't matter where it is.
05:29So, drush -y pm-uninstall comment.
05:36The Comment module is now completely disabled and uninstalled.
05:40The inverse is also possible using the Command Project Manager enable, aliased as
05:44just en, drush help en.
05:48Enable will enable the extension along with any dependencies.
05:53Enable will by default also download any libraries that may be used by the module.
05:58For example, the devel module downloaded earlier can use fire PHP.
06:03Let's enable the devel module now to see the automatic Library download: drush -y en devel.
06:14Devel was enabled but if you don't have subversion installed then fire PHP
06:19was not downloaded.
06:21This is one of the admittedly goofy bits of Drush.
06:24I will occasionally find these little weirdnesses like commands not working
06:27quite right and it turns out that there's a missing dependency that it
06:31doesn't explicitly state.
06:33That's why I went through the trouble of making sure you had Wget an Unzip
06:37installed, as that's caused problems in the past when I was trying to figure out
06:40why it was failing silently.
06:42In this particular case, you can use the package manager of your system
06:45to install subversion.
06:47In this case, I'm going to use "sudo apt-get install subversion".
06:58Then, "drush -y", I am going to disable devel.
07:04And then, "drush -y en devel" to enable it.
07:11This time fire PHP was installed.
07:14One more trick, were you ever curious how many modules were installed on a site?
07:18I will list every extension of type module in package core that is enabled.
07:22I will use an additional argument "--pipe" to only show of module names: drush pml
07:29--type=module package=core status=enabled, and then, --pipe.
07:38As it stands this would work, but I don't want to count each of these lines.
07:42I can pipe the results into the WC or Word Count command with the option -l to
07:48count the number of lines. So, Space pipe wc -l.
07:54There are 28 modules in core that are enabled right now.
07:58This technique is useful, especially when trying to make the case that there are
08:01a large number of modules on a site and someone says, "it's not so bad."
08:06Now there's a quantifiable number to back up your claims.
08:10Now that I've demonstrated the foundation of listing, enabling, and disabling
08:14extensions, let's explore theme management and variables.
Collapse this transcript
Theme and variable management
00:00Downloading and enabling themes is the same as downloading and enabling
00:04modules, to a point.
00:06I will describe the differences in how to mitigate them.
00:09First, let's list the themes that are currently available, drush pml --type=theme.
00:17There are four themes and two of them are enabled.
00:20However, Drupal themes have some differences for modules, in particular there
00:24are default themes which are used unless otherwise specified and admin themes
00:29which are used on admin pages only.
00:31The project manage list doesn't show this information.
00:34These settings are stored as Drupel site variables.
00:37In Drupal development, there are two functions, variable_get and variable_set, that
00:42are used to retrieve and save settings and other one-off types of information
00:46from hardcoded settings in settings.php and from the database.
00:51Drush provides an interface to these site variables with a variable_get and
00:54variable_set commands aliased as vget and vset.
00:58I will start with variable_get, help vget.
01:02vget takes one argument, the partial or complete name of the variable.
01:07If ommited, vget will return all variables.
01:11The next bit isn't explicitly documented so I will demonstrate it for you.
01:15The default theme is saved in a variable named theme_default.
01:20Let's get the value of theme_default now:
01:23drush vget theme_default.
01:27Currently the default theme is bartik.
01:29I am going to switch to the garland theme which is included in core but not enabled.
01:34First, I'll enable garland using project manage command enable garland, drush -y en garland.
01:42Then, I will set the variable using the vset command, drush help vset.
01:47Variable set has a lot of options, but in the simplest mode it can just set a
01:53given value to a particular named variable name.
01:56So in this case, drush vset theme_default, to "garland".
02:04Theme default is now set to garland.
02:06Verify this by using vget again: drush vget theme_default, and it's set to garland.
02:16Switch back to the browser and go to the homepage and reload, make sure that you
02:23can see the difference.
02:24As the administrative theme is distinct from the theme default there is a
02:28different variable, going back to the terminal use vget again, but this time on
02:33the variable admin_theme, drush vget admin_theme.
02:40This time two variables will be shown, by default vget searches for variables
02:44that contain the search term.
02:46To be more specific pass an additional option called Exact, which will only
02:51match the exact variable:
02:52drush vget admin_theme --exact.
02:59This is functional but what if I wanted to change to a different admin
03:02theme such as Rubik.
03:03Three steps are required, first, download the Rubik theme which also has a soft
03:08dependency with the Tao theme.
03:10Usually, dependencies are auto enabled, but in this case it hasn't been
03:14explicitly defined by the theme author so it will need to be explicitly
03:18downloaded and enabled:
03:20drush dl rubik tao.
03:25Next, enable the Rubik in Tao themes.
03:28So, drush -y en rubik tao.
03:34Finally, set Rubik as the admin theme.
03:37If there was one exact match, variable set will just set that one variable and
03:42will not set the additional variables.
03:44If there is not an exact match, like when a variable has never been set, then the
03:48exact option will allow the variable to be set.
03:52So in this case I'll just type, drush vset admin_theme rubik.
04:01Return to the browser and navigate to the Configuration page to see the
04:05difference, which is very striking.
04:08I'm going to put the admin theme now back to default:
04:11drush reset admin_theme seven.
04:16Going back to the browser and refreshing.
04:20And it's back to normal.
04:21The vget command can be very useful for tracking changes over time on UNIX like systems.
04:26On the configuration page go to site information.
04:31Now we will switch back to the terminal for just a moment.
04:34By default, variable get will return all variables.
04:37I will write every variable in this site to a flat file before I make a change
04:42then do a second file and compare the differences to see what was written.
04:45This can be useful when storing variables and code, either in settings.php or
04:51when explicitly setting a variable in a hook update.
04:54I'm going to give the command "drush vget" and write the output to a file named "before".
05:03Next, go to the browser and set the site name to Drush and the slogan to "a
05:08command line shell and scripting interface for Drupal".
05:14Save the changes then navigate to the site home page.
05:20The new site name and slogan are shown.
05:22Return to the terminal then dump the variables into a file named "after":
05:27drush vget to after.
05:32Finally, use the diff command to show the difference between the two files: diff before after.
05:39There are two symbols the greater than symbol indicates that something was
05:42written and the less than symbol indicates that something is removed.
05:46With this view, I can see that not only were the variables, site name and site
05:50slogan, written but so are some other values as well.
05:53If I wanted to hardcode these variables in the settings.php I can use another
05:58feature of variable get, the pipe option.
06:01In this context, I will render the variables as a line of PHP:
06:05drush vget site_name --pipe.
06:11And, drush vget site slogan --pipe.
06:18I can take these two lines and copy them into settings.php, renaming the dollar
06:23$variables to dollar sign $conf to force the site name and slogan to be
06:27whatever I specified.
06:29For more information on defining variables in the site's settings.php conf
06:33array, see drupal.org/node/1525472.
06:41I have demonstrated how to enable, disable, and set the site default and admin
06:45team without using the site interface.
06:47This can be extremely useful, especially when a mistake was made when developing
06:51a theme and a failsafe is needed.
06:53In the next segment, I will demonstrate how to manage users, including creating
06:57and disabling users, then changing passwords.
Collapse this transcript
User management
00:00Managing users is an everyday task for many Drupal site administrators.
00:04So Drush provides an interface for that as well.
00:07Let's start with getting information about a user.
00:09drush help user information.
00:14The User information command, aliased as uinf, displays information about a user.
00:20The argument passed as a comma separated list of usernames UIDs and email addresses.
00:26Right now there's only one user on the system, the admin user that was created
00:30during site installation.
00:32So I will get information about that user, drush uinf admin.
00:38The user id, name, mail, roles and status are displayed.
00:44Additional information can be shown using the option --full.
00:50The full view is a bit more extreme and is useful for low-level debugging.
00:54For example, the password is shown in a sense.
01:00It's the hashed password not the actual password which in this case is admin.
01:04A common problem is that users are constantly forgetting their passwords.
01:08Drupal's Password API hashes passwords using a secured stretched hash, meaning
01:15that it's both salted and hashed multiple times to increase the complexity of
01:19the stored password to reduce the risk of brute force decryption.
01:22Due to these privacy and security restrictions this means the passwords cannot
01:26be read even by administrators, despite whatever a client may request or demand.
01:32Instead, Drupal's administrative interface provides a mechanism that allows
01:36users to request one time Logins and allows administrators to arbitrarily set a user's password.
01:43I will demonstrate both of these techniques using Drush.
01:46First, setting passwords manually, this is useful when working on a local
01:50duplicated copy of a client site and the particular password is not known.
01:55drush user password, or just aliased as upwd sets, the password for a user.
02:03The only argument is the username and there is a required option, yes
02:06that's oxymoronic but it is required names password containing the new
02:10password in plain text.
02:12So I am going to set password for admin with the required option, password =hello.
02:20I can also put quotes around the password if the target password contains quotes or spaces.
02:25"Hello" isn't a good password so set it back to admin which is still insecure but
02:29easy to remember in a development environment.
02:32drush upwd admin password=admin.
02:38The second technique, generates a one- time login URL which can be given to a user.
02:44This is preferable to setting a password for user as administrators should never
02:48know a users password.
02:50The user login command aliased uli will generate these log in URLs for a given
02:56user, drush uli admin.
03:01Depending on the way the site was set up Drush may not know the actual site URL
03:05and out-of-the-box the URL is not set which is why it's showing as http default.
03:11Always look at the output before blindly passing it on to the user.
03:15These generated one time log-ins are not emailed by Drush, the administrator
03:19needs to manually use these URLs in whatever way they see fit.
03:23Drush user interaction goes beyond passwords, users can be created, blocked and
03:28unblocked and even canceled.
03:30I will start by creating a test user using the User Create command aliased as
03:35ucrt, drush help ucrt.
03:39User create takes an argument containing the username followed by the two
03:43options with a mail and password.
03:46drush ucrt test mail="test@ example.com" and password=test.
03:58Now if I get user information on the test user, drush uinf test, I will see the
04:04same information as I was shown when I created the user.
04:07While user create is used on one user at a time the block and unblock commands
04:13will work on multiple users at a time.
04:15The user list can be separated by commas and the users can be specified by
04:19UID, email or username.
04:22Be careful with this command as there is no prompt and Drush will respect
04:26whatever email preferences that have been set on the site such as not notifying
04:30on blocks and sending an activation email when unblocking.
04:33To block a user I would use the user block command aliased as ublk followed by
04:39an argument containing the users.
04:41drush ublk, let's get the help for that, I will block both the admin user by UID
04:48and the test user, by user name.
04:53Notice that I am not using the additional options specifying that I'm using a
04:57UID or username, Drush will do the work for me.
05:01Verify that the admin user is blocked with the command line. drush uinf 1.
05:08Then, return to the browser and attempt to navigate to a page.
05:15Being blocked, the admin user is kicked out.
05:20The user status is shown as blocked, given that it's easy to block someone
05:24without a prompt the block can be also similarly removed, user unblock operates
05:29in a very similar manner and has a similar alias, uublk.
05:34I will leave the test user blocked, drush uublk 1.
05:41I'm shown an error regarding e-mail as my local development environment was
05:44not set up to send email at this time and by default Drupal will send an email
05:49upon account activation.
05:51Finally, if I want to gracefully get rid of an account I can cancel a user using
05:55the user cancel command.
05:57Ironically aliased as ucan, drush help ucan.
06:03By default all contents owned by the user reverts to UID 1.
06:07I will cancel the test account now as I'm done with it.
06:11User cancel takes one argument a single user to cancel, an optional argument
06:16will just arbitrarily delete all content created by the user as well, drush ucan
06:21test delete content.
06:25Following a prompt the user in all their content will be deleted.
06:29Throughout this chapter I've covered a number of core functionalities for
06:34everyday operation, including: site installation and introspection for building a
06:38site from the ground up and getting a high-level perspective of site
06:41configuration, listing and managing modules which is useful for downloading,
06:46enabling and disabling modules, theme and variable management using variable
06:51set and get in user management including creation, blocking and unblocking and cancellation.
06:58In the next chapter, I will discuss more advanced and low-level site
07:02management techniques
Collapse this transcript
3. Site Management Techniques
Controlling cache and cron
00:00Drupal is like an engine, a complex system with many moving parts working in
00:04conjunction with one-another to deliver power.
00:07By opening the metaphorical hood and working directly with the engine, using the
00:11right tool, a properly equipped site administrator can quickly perform
00:15potentially cumbersome tasks with ease.
00:18This chapter will cover a number of tools and techniques useful for performing
00:22low-level operations on a Drupal site.
00:24Out of the box, Drupal provides a number of caching mechanisms to improve site
00:29performance and avoid heavy or repetitive tasks.
00:32For example, both the menus and the blocks are extensively cached and Drupal
00:38gives precedence to these caches over configuration stored in code.
00:42This can present a problem when developing modules as code changes will not be
00:46immediately shown on a site.
00:48Additionally, when transferring a site between hosting environments, cache
00:52settings for file locations and paths can cause problems when attempting to
00:55access the transferred site without clearing the cache which tends to result in
00:59an incomplete or broken site.
01:02Log back into the site: admin, admin.
01:07Drupal provides an interface for clearing all caches deep within the Admin menu.
01:11If you go to Configuration>Performance, you see a button, Clear all caches.
01:18It's time-consuming to wade through the menus to find this button and sometimes
01:21there's no need to clear every cache, only a certain cache such as the menu or
01:26aggregated and compressed CSS files.
01:28Drush provides a mechanism to handle these issues with the Cache Clear command
01:32aliased as cc, drush cc --help.
01:38The Cache Clear command takes an optional argument, the name of the cache to clear.
01:42If the argument is omitted, Drush will give a choice of the available caches,
01:46type: drush cc, and press Enter without any arguments.
01:51All will do the same as clear all caches and often this is used as a magic
01:55bullet to fix strange caching issues.
01:58Do be cautious however, as this will degrade performance for the next few page
02:01views until the caches are regenerated.
02:04Press 1 to clear all caches.
02:06The same command can be executed by specifying "all" as the argument.
02:10I use this often enough that it's practically muscle memory, drush cc all.
02:16The second cache to clear, drush, is specific to commands used by Drush.
02:21If new Drush functionality was installed in the module, but Drush does not
02:24recognize the command when accessed, clear the drush cache.
02:28I personally have not had to use the clear drush cache very often.
02:32Theme registry is useful when developing themes and adding a new template.
02:37The rest of the options are straightforward, the menu is the menu cache; css-js
02:41clears the aggregated in cache style sheets and JavaScript files; block clears
02:46the block cache, and so forth.
02:48To explicitly clear one of these caches either use drush cc, press Enter and
02:52type the number of the selection, or give the machine name of the cache to clear
02:56such as: drush cc menu.
03:00Caches typically have an expiration date and therefore have a
03:02chronological context.
03:04With that in mind, caches are not the only time-based mechanism that executes in Drupal.
03:10A cron job is a time-based event that executes some regularly scheduled
03:15operation such as: checking site updates, indexing site content with the search
03:20module, importing site content from a third-party, and so forth.
03:24In Drupal 6, cron execution needed to be set up manually or leverage the
03:28contributed module poormanscron, which triggered these time-based events after a
03:33regular page load from a visitor.
03:35poormanscron was included in Drupal 7 Core eliminating the need for additional
03:40configuration or module installation.
03:42However, regardless of the mechanism that triggers them, sometimes it's useful
03:46to manually execute these time-based events.
03:49The drush command cron, which has no alias, runs all cron hooks for every active
03:57module in a given site.
03:58The drush cron command takes no arguments or options: drush cron.
04:04Upon completion, feedback is given.
04:06On the topic of feedback, the Drupal logging system contains a vast wealth of
04:10feedback and debugging information from various side events.
Collapse this transcript
Reading the "watchdog" logs
00:00The term 'watchdog' is a bit of a Drupal anachronism, as it refers to a
00:05deprecated module for monitoring a Drupal site and recording system events for
00:09review and debugging.
00:11However, the name persists in both function and table names individual triggered
00:15by the word 'watchdog' tends to get the message across.
00:18Starting in Drupal 6, Drupal defaults to using the dblog module for logging to
00:23the watchdog database table and these logs are visible in the site.
00:27From the browser, go to Reports, then Recent log messages.
00:32There are a number of filters that can be applied in a single button to
00:36clear all log messages.
00:38It's functional, but it's a bit cumbersome.
00:42Switching back to the commands line, I will use Drush to retrieve and search for log messages.
00:47There are three commands relating to watchdog, the first, "watchdog list" aliased
00:52as wd-list shows a list of available message types and severity levels in a very
01:00similar way to the select list from the browser interface.
01:03And it will prompt the user for a choice to show messages, drush wd-list.
01:09Type "1" to see a list of access denied messages.
01:13Next, the proverbial firehose, watchdog show, drush ws.
01:19It's a much more powerful tool for displaying messages and it has a number of
01:23useful options, drush ws --help.
01:27A single argument allows the operator to specify a particular watchdog log id
01:32for additional details.
01:34If emitted, watchdog show will default to the last 10 messages.
01:38This option can be combined to provide strict controls over what is shown.
01:42For example, drush ws --count =5 --type=system.
01:49This will show five messages which in this case are just info.
01:53Combine the type and severities shown from the watchdog list with the options in
01:57watchdog show and the potential power of this tool can be realized.
02:00One of the options, tail, is an easily overlooked, but extremely useful utility
02:06that will continuously show watchdog messages as they are generated in
02:09real-time until interrupted.
02:11For example, I will launch it for failed logins, drush ws --type="access denied" --tail.
02:24Keeping the council window open, I will open a browser, log out, and attempt to
02:30access a page that I do not have access to, such as /admin.
02:36Notice the new log entry shown in watchdog show with a type access denied and
02:41the message containing the URL that was attempted to be accessed.
02:44To break out of this view, press Ctrl+C.Reviewing logs can turn up
02:49important items that may have gone unnoticed such as the need to update
02:52Drupal or a module.
Collapse this transcript
Updating Drupal and modules
00:00Keeping Drupal in the various modules up-to-date can be a pain.
00:03In Drupal 6, downloading and extracting individual modules was cumbersome and
00:08repetitive in a very manual process.
00:11In Drupal 7, module updates were streamlined through the browser interface, but
00:15it still took a number of steps.
00:17To make this task easier, Drush provides some utilities that will update both
00:21core and contributed modules.
00:23To demonstrate these utilities, I'm going to quickly set up an intentionally
00:27out-of-date site using Drush package manager download and site install.
00:32Change directory out of the siteroot.
00:36Next, download an older version of Drupal, I'll use Drupal 7.15, so, "drush dl drupal-7.15".
00:48Change directory to "drupal-7.15" and then we'll perform a site install again.
00:54This is going to overwrite the database used by Drupal-7.17.
00:59If you're sure that there's nothing to lose, say yes to the prompt, so, drush si
01:04--db-url=mysql://root:root@127.0.0.1: 3306/drush, and then, account-pass=admin.
01:26If you're sure, say yes.
01:30Next, download an old version of the Devel module, in this case 1.2, drush dl devel-1.2.
01:36Enable devel in one command without saying yes, drush -y en devel.
01:51Now that an out-of-date version of Drupal has been installed and an out-of-date
01:54module has been enabled, execute the cron;
01:57this will among other things check for updates, drush cron.
02:04Notice that this time cron attempted to send an email.
02:07This is because Drupal is not up-to-date.
02:10Open a browser and navigate to Druple-7. 15 and log in using the admin username
02:19and password, navigate to Reports>Status report.
02:31The Drupal core update status is not secure, out-of-date and Module and theme
02:37update status is also out-of-date.
02:40The devel module can be updated through the web interface, but when I click on
02:43information about the Drupal update, I see that this is a manual update.
02:50Normally, this would be a big production needing many steps, but Drush allows
02:54everything to be done in one Command.
02:57It's best practice to back up the siteroot and database before doing an
03:00arbitrary update, as usually module and core updates go smoothly, but there's
03:05always the edge case that can give you a in capital letters a Very Bad Day,
03:09if you don't back up.
03:10Out of the box and by default, project manager update will also back up the
03:15replaced code automatically, but not the database, I'll go into greater detail
03:20about manually archiving and restoring sites in the next segment.
03:23For now, since this is a freshly installed demonstration site, it's safe to proceed.
03:28The Drush command pm-update code aliased as "drush upc" is a powerful tool;
03:37upc will display the currently available information for Drupal core and all
03:41enabled projects that allow updating to the latest recommended releases.
03:45I look at the help shows the scope of all the options available.
03:52If I wanted to exclude core from the updates or only apply security updates,
03:57there are options that are available for that level of granularity.
04:01For now, I'll stick with an arbitrary update.
04:05For database updates the manual command, drush pm-updatedb, which is aliased as
04:13updb, replaces the need to navigate to update.php with the browser.
04:21While both of these commands are available separately, they've been combined
04:25for convenience into one mega command, project manager update, aliased as "up", drush up.
04:32Following the update, database updates will be applied.
04:36Each step provides an interactive yes or no option which can be overridden with
04:40-y like other commands, drush up.
04:45Information about all the pending updates and the potential consequences of
04:49proceeding are shown.
04:50Am I sure that I wish to continue? Yes.
04:55Do I really want to continue with updating Drupal core? Yes.
05:00This pause is the downloading and extraction of the updates.
05:06Additionally, all database updates are shown and the option to continue is given.
05:11drush up, automatically downloads, installs both the core upgrade and module
05:15upgrade, then applies the pending database update.
05:19Next, execute cron to check for updates, drush cron.
05:25Navigate back to the status report, everything is now shown as up-to-date.
05:34Now in a production site, additional care should be taken to back up both the
05:38database and files of a site.
05:40Drush provides convenient utilities to archive and restore a site.
Collapse this transcript
Archiving and restoring sites
00:00To give context for archiving and restoring sites, I will first describe the
00:04three primary structural components in a Drupal site.
00:07The database, which stores all the site content; the codebase which contains all
00:12the executable scripts such as Drupal core, modules, and themes;
00:16Drupal specific hosts typically store the codebase in a revision controlled
00:19repository; and files, which contain generated and uploaded files such as
00:24images, icons, and other media.
00:27By default, these files reside in the same web root as the codebase.
00:31Before performing updates or making major changes to a site, it's best practice
00:35to back up the site first.
00:37I'll demonstrate how to back up and restore the database, then the entire site
00:41including the codebase and files.
00:44Drush provides a built-in utility for creating a database dump known as
00:47sql-dump: drush sql-dump --help.
00:55This exports a Drupal site database as SQL using MySQL dump or equivalent.
01:01As of this writing, this command has known compatibility issues with Drush for Windows.
01:05sql-dump takes no arguments, only parameters.
01:09By default, sql-dump exports the entire schema and data.
01:13Unless otherwise specified, the database dump is placed in the drush-backups
01:18directory in the user's home directory.
01:21Typically, it makes sense to specify the location of the file.
01:25I'm going to back up the database to the directory above the Drupal root,
01:28something to keep in mind.
01:30Drush uses relative file locations to the Drupal root or absolute paths.
01:34Using tilde (~) to indicate a home folder will not work.
01:38I prefer to add a date to the file name to give context, and I'll use generic
01:42placeholders for demonstration, drush sql -dump, and then I'm going to specify the
01:49result-file =, then back one directory, backup-YYYY for the year, month (MM),
01:58and day (DD) dot sql.
02:01Now that the database dump has been created, I'm going to import the contents.
02:05Before I can do that, I need to get rid of all the tables in the Drupal database.
02:09If I don't, then very bad things will happen and the site will be broken.
02:13I'm going to use the command: drush sql-drop.
02:17First, I'll show the help.
02:19Only use this command if you know exactly what you're doing, as this is a
02:22destructive command and will wipe out all the tables in the site's
02:25database, drush sql-drop.
02:29A prompt will be given, am I sure? Yes.
02:32Now that the contents of the database have been completely removed, I will now
02:36import the site dump created previously using drush sql query aliased as sqlq: drush sqlq.
02:43SQL query executes a query against the site database.
02:50I will specify the location of the database dump using the option file which
02:54takes the relative path to the Drupal root.
02:56This command does not prompt for confirmation, so be aware of what you're
02:59doing: drush sqlq --file=../backup, and then the name of the file that you wish to restore.
03:12No messages are shown unless there's a problem.
03:15Verify that the site has been properly restored by returning to the browser and
03:18reloading to see a working site.
03:25Next, I will archive and restore the entire site.
03:28The command archive dump, aliased as ard, backs up a site code, files, and
03:36database into a single tar file.
03:38Archive dump takes one optional argument, the sites to be dumped.
03:42This is only useful with multi-sites.
03:45I'm going to specify the destination of the archives as the parent directory.
03:49As the resulting file is a tar archive I will need to specify .tar as the file
03:54extension. Similar to the sql-dump, I prefer to name the archives with a date
03:58for clear distinction: drush ard -- destination=../backup-YYYY-MM-DD.tar.
04:12When complete, Drupal will show the site status and tell where the archive was created.
04:16I'm going to drop the database now to ensure that everything is removed, drush
04:21sql-drop, am I sure? Yes.
04:24Change directory back to the parent directory, then remove the archived site:
04:32rm -Rf drupal-7.15.
04:38Let's take a look at the archived contents.
04:41Normally, there is no need to do this, but it's useful to know what's inside.
04:45Opening the sandbox folder, I'm going to use double-click on the tar file to
04:50look at the contents.
04:53Inside, there is a folder containing the siteroot, a database dump named after
04:57the database used, and a manifest.ini, which describes the context from which
05:01the archive was created from.
05:03Looking in the sandbox directory, I'll also remove the drupal-7.17 directory:
05:09rm -Rf drupal-7.17.
05:14Between dropping the table and removing these folders everything has been removed.
05:18Remember to leave the backup archive.
05:21The Drush command, "drush archive restore" aliased as arr, expands a site archive
05:27into a Drupal website, drush arr -help.
05:32Archive restore takes two arguments:
05:36the first is the path to the file containing the archive and the second optional
05:40argument is the name of the sites within the archive to be extracted.
05:43Again, this is only useful for multi-sites.
05:44An option for destination allows me to specify where the archive is to be extracted;
05:52the default is the current working directory.
05:56I'm going to restore the site from the archive.
05:58Since I changed directories, the path to the archive is slightly different:
06:02drush arr backup.tar.
06:09Open the browser and refresh the site.
06:15The site has been fully restored.
06:16It's a best practice to clear the cache after restoring from a backup,
06:20especially if the archive was restored in a different environment from which it
06:23was created, drush cc all.
06:28In this chapter, I've demonstrated a number of everyday activities that I use on
06:32a regular basis including controlling the cache and cron, reading the watchdog
06:37logs, updating Drupal and modules, and archiving and restoring sites.
06:43One question remains, where to go from here?
Collapse this transcript
Conclusion
Where to go from here
00:00Throughout this course, I've provided context for what Drush is and how it can
00:04be used on a daily basis to simplify Drupal site administration.
00:08I've covered a large number of commands and command aliases, and there's a lot to remember.
00:13To help, I've written a quick reference document and provided it as a free download.
00:18The Quick Reference includes all of the commands covered in this course and
00:21several useful examples.
00:23Feel free to print out the Quick Reference and give it to anyone who may find it useful.
00:28I've not covered every command available in Drush.
00:31There are several dozen commands available in total, many of which have their
00:34own arguments and options.
00:35I'll share a technique I used to quickly search for Drush commands.
00:39I pipe the output of Drush into grep case-insensitive and give it a word
00:43that I'm looking for.
00:44For example, if I want to search commands for download, I would type the following:
00:49drush | grep -i download.
00:56Drush also includes additional in-depth documentation beyond what is shown in the help files.
01:02To see a list of all topics available type "drush topic", type the number of the
01:08topic that you wish to see, or press zero to cancel.
01:13Downloading particular versions of Drupal, modules and themes, applying patches,
01:18installing libraries, and including custom functionality can be an arduous
01:22process if done manually.
01:24A formerly contributed project, Drush make is now available in Drush and
01:29allows for the use of a standardized script, known as a Make file to create a Drupal code base.
01:34For more information on the Make command, type "drush help make".
01:41Drush make is very useful when creating a site-building process in conjunction
01:45with the continuous integration or delivery process.
01:48Drush also has the ability to securely connect to remote sites via SSH and
01:53perform commands remotely, storing connection and site information in local
01:56configuration files.
01:59The end result is that multiple sites can be aliased and acted on as if they were local.
02:03Drupal site aliases are also provided by several commercial Drupal hosts which
02:07facilitates remote administration.
02:10For more information, look at "drush site -alias --help", and "drush docs-aliases",
02:18and press Q to exit.
Collapse this transcript
Goodbye
00:00Drush is a fantastic utility for managing Drupal site installations, and I use
00:04it daily for both administration and development.
00:07By providing a guided introduction into this richly populated world of
00:10commands, I hope to have given enough context and examples to increase your
00:14comfort level enough to discover new functionality and to leverage Drush to its fullest abilities.
00:19I greatly enjoyed writing and recording this course and I appreciate your time.
00:24Please take a moment to provide some feedback on the course homepage.
00:27Thanks for watching!
Collapse this transcript


Suggested courses to watch next:

Drupal 7 Advanced Training (7h 50m)
Tom Geller



Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,069 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked