20,39 €
This book is a best fit for backend developers with a basic knowledge of Drupal's APIs and some experience using the command line. Perhaps you already worked on one or two Drupal projects, but have never dived deep into Drush's toolset. In any case, this book will give you a lot of advice by covering real-world challenges in Drupal projects that can be solved using Drush.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 198
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2012
Second edition: January 2015
Production reference: 1240115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-378-6
www.packtpub.com
Author
Juampy Novillo Requena
Reviewers
Greg Anderson
Chris Burgess
Jonathan Araña Cruz
Jeremy French
Todd Zebert
Commissioning Editor
Dipika Gaonkar
Acquisition Editor
Meeta Rajani
Content Development Editor
Anila Vincent
Technical Editor
Arvind Koul
Copy Editor
Relin Hedly
Project Coordinator
Neha Bhatnagar
Proofreaders
Bridget Braund
Ameesha Green
Indexer
Tejal Soni
Production Coordinator
Alwin Roy
Cover Work
Alwin Roy
Juampy Novillo Requena started working as a web developer in London. After spending a few years developing with plain PHP, Symfony, and Ruby on Rails, he discovered Drupal. Drawn by the Drupal community and the mind-blowing effect of getting a project done 10 times faster than before, Juampy has never looked back.
Since then, he's become more and more involved in the issue queues, which in turn led him to become a maintainer of core and contributed modules. He organizes events, gives sessions at national and international conferences, and has written the book Drush User's Guide, Packt Publishing. He feels privileged to experiment, have fun, and be challenged every day. He is known as juampy on Drupal.org and IRC. His Twitter account is @juampy72.
This book is the result of my two years working at Lullabot. Most of the contents explained here were originated by discussions or contributions within the team. I am very thankful to the team who worked on the MSNBC project, where we collaboratively developed and implemented best practices that are represented in this book.
I also want to thank the technical reviewers; their suggestions and corrections leveraged this book to a higher level.
Finally, a personal acknowledgement to the city of Niamey, Niger, where I did most of the writing.
Greg Anderson is an open source contributions engineer working on Drupal and WordPress at Pantheon in San Francisco. He has been contributing to Drush since just before the release of version 2, and remains an active co-maintainer to this day.
Chris Burgess is currently making the world better by building open source tools for activist and nonprofit organizations to campaign and communicate. He has been developing with Drupal since 2006, and he is immensely grateful to the Drupal and wider open source communities for the learning and sharing environment that they foster. Chris is based in Dunedin, New Zealand, with his two sons, Hunter and Rowan, and partner, Saira. He works for Fuzion Aotearoa, and you can reach him at @xurizaemon on Twitter, xur1z on IRC, or his Drupal.org profile at https://www.drupal.org/u/xurizaemon.
Jonathan Araña Cruz is a co-maintainer of Drush. He combines both sysadmin and Drupal development work. Jonathan has contributed several modules to Drupal, and as a sysadmin, he manages Infrastructure as Code with Puppet.
Jonathan's Drupal profile can be found at https://www.drupal.org/u/jonhattan.
Jeremy French has worked in web development for over a decade, floating through a wasteland of bespoke Content Management Systems, before finding Drupal. He has developed sites for a number of household names and blue chips, as well as a few interesting start-ups. Currently, he is working for a small agency, living the dream of distributed working.
Todd Zebert has been involved with Drupal since early version 6. He creates websites and web apps with a variety of technologies. Currently, Todd works as a lead web developer for Miles.
Todd has a diverse background in technology, including infrastructure, network engineering, project management, and IT leadership. His experience with web development started with the original Mosaic graphical web browser, SHTML/CGI, and Perl. His fondness for Drupal and his interest in workflow, efficiency, repeatable best practices, and DevOps drives his interest in Drush.
Todd is an entrepreneur involved with the start-up community. He's a believer in volunteering, open source, and contributing back. He's an advocate for Science, Technology, Engineering, Art, and Math (STEAM) education.
I'd like to thank the Drupal community, which is like no other.
Finally, I'd like to thank my pre-teen son with whom I get to share my interest in technology and program video games together.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
In this book, I share with you how I use Drush in my day-to-day work. When working on Drupal projects, Drush is omnipresent. It is a key tool to debug code, run small scripts, and discover APIs. However, this is just the beginning; Drush's real potential comes when teams use it to define a development workflow.
Chapter 1, Introduction, Installation, and Basic Usage, begins with Drush's requirements and installation and then shows its basic usage through examples.
Chapter 2, Keeping Database Configuration and Code Together, explains how to export configuration from the database into code in order to share it with the rest of the team and other environments.
Chapter 3, Running and Monitoring Tasks in Drupal Projects, gives different options to run tasks in Drupal projects such as cron, Batch API, and custom scripts.
Chapter 4, Error Handling and Debugging, explores tools that help us catch and process errors, so as to navigate through the available hooks and functions in our project.
Chapter 5, Managing Local and Remote Environments, unveils all the magic behind site aliases using a typical Drupal project that involves production and development environments.
Chapter 6, Setting Up a Development Workflow, leverages all the concepts covered in the book by defining a development workflow for a team.
Here are the system requirements to run the examples in the book:
This book will fit best to backend developers with a basic knowledge of Drupal's APIs and some experience using the command line. Perhaps, you already worked on one or two Drupal projects, but have never dived deep into Drush's toolset. In any case, this book will give you a lot of advice by covering real-world challenges in Drupal projects that can be solved using Drush.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you really get the most out of.
To send us general feedback, simply e-mail to <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata SubmissionForm link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem..
Drush is a command-line interface for Drupal. It can also serve as an alternative to write scripts using PHP instead of BASH. The Drush ecosystem is vast. Every year, at DrupalCon, the Drush core team gives an update on the bleeding edge features being developed by them and by contributors all over the world.
Tasks such as clearing caches, running database updates, executing batch scripts, and managing remote websites are just a glimpse of what you can do with Drush.
Here is an example. Imagine that you have pushed new code for your website and need to run database updates. Normally this would involve the following steps:
Now, here is how you can accomplish the preceding steps with Drush:
That's it. We did not even have to open an SSH connection or a web browser. The first command created a database backup and the second one executed pending database updates. In both these commands, we used @example.prod, which is a Drush site alias used to load configuration details about a particular site. We will see Drush site aliases in detail in Chapter 5, Managing Local and Remote Environments.
Drush is highly customizable. You can adjust it to fit a specific workflow. This is especially helpful when working on a Drupal project within a team; you can define security policies, wrap commands with sensible defaults, sanitize a copy of the production database automatically, and so on. This is the area that this book will focus on. We will go through some common processes during a Drupal project and discover how we can automate or simplify them using Drush. Let's start!
This chapter is an introduction and will cover the following topics to get you up to speed:
The following are the installation requirements for Drush. If you have already installed it, simply make sure that you are running version 7.0.0-alpha5 (https://github.com/drush-ops/drush/releases/tag/7.0.0-alpha5) or higher by executing drush --version in the command line, and skip forward to the next section of this chapter.
Drush works on Unix-like operating systems (such as Ubuntu and OSX) and Windows operating systems.
If you use Windows, consider using something like VirtualBox (https://www.virtualbox.org) to install a virtual machine that runs, for example, Ubuntu (http://www.ubuntu.com). If you still want to use Drush on Windows, there is an installer available at http://www.drush.org/drush_windows_installer. Note, however, that the installer installs an older version of Drush, so some of the contents of this book won't work.
Let's start by making sure that you have PHP 5.3.0 or greater installed. To do so, open a terminal and run the following command:
The output should look something like the following code screenshot:
As you can see, I am using PHP 5.5.9. If you get a Command not found message or your version is lower than 5.3.0, you will need to install or upgrade PHP. Refer to your vendor documentation to do this as the steps will vary.
On Linux and OSX platforms, the recommended way to install Drush is through Composer (https://getcomposer.org), a dependency manager that has become the standard in the PHP world. Installing Composer can be accomplished with the following commands:
If you find any issues while running the preceding commands or while installing it through a packaging system such as homebrew, then take a look at the official installation instructions for Composer (https://getcomposer.org/doc/00-intro.md#globally-on-osx-via-homebrew). Once you have completed the installation, you can verify that it works by running the following command:
If you have already installed Composer, make sure that it is up to date by runningcomposer self-update (https://getcomposer.org/doc/03-cli.md#self-update).
At the time of writing this book, the latest available version of Drush is 7.0.0-alpha5 (https://github.com/drush-ops/drush/releases/tag/7.0.0-alpha5). This is the version that we will use. The Drush core team does a fantastic job of keeping backwards compatibility between major versions, so if you have already installed a more recent version of Drush, you should be okay as practically all the examples in the book will work.
Let's go ahead and install Drush. Once Composer has been installed (see the previous section on installing Composer), you can install Drush with the following command:
The preceding command has downloaded Drush 7.0.0-alpha5 into $HOME/.composer/vendor/bin/drush. In order to use Drush from anywhere in the system, we need to make sure that Composer's bin directory is present at our $PATH environment variable. We can do so with the following commands:
Note the use of $HOME and $PATH, which are environment variables. $HOME contains the location of your home directory, while $PATH represents a list of directories to look for executable files. You can view the contents of these variables by executing echo $HOME or echo $PATH. Take a look at your home directory to check whether there is .bash_profile, .bash_login, or .profile file at $HOME. If you find them, adjust the preceding commands, so the $PATH variable is adjusted in these files as well.
Finally, we can test that Drush has been installed successfully and contains the right version:
If you prefer to install Drush manually, then follow these steps:
The main README file at the Drush repository has a great section on POST-INSTALL tasks (https://github.com/drush-ops/drush#post-install) with additional information on configuring PHP and extra settings for environments such as MAMP. It's worth taking a look at it.