Book Image

Drush for Developers - Second Edition

By : Juan Pablo Novillo Requena, Juan P Novillo Requena
Book Image

Drush for Developers - Second Edition

By: Juan Pablo Novillo Requena, Juan P Novillo Requena

Overview of this book

Table of Contents (13 chapters)
Drush for Developers Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Keeping Database Configuration and Code Together
Index

Installation requirements


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.

Operating system

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.

PHP

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:

$ php -v

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.

Installing Composer

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:

$ cd $HOME
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

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:

$ composer about 
Composer - Package Management for PHP 
Composer is a dependency manager tracking local dependencies of your projects and libraries. 
See http://getcomposer.org/ for more information. 

Note

If you have already installed Composer, make sure that it is up to date by running composer self-update (https://getcomposer.org/doc/03-cli.md#self-update).

Drush installation on Linux and OSX

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:

$ composer global require drush/drush:7.0.0-alpha5 -v
Changed current directory to /home/juampy/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
    - Installing drush/drush (7.0.0-alpha5)
    Downloading: 100%         
    Extracting archive
drush/drush suggests installing youngj/httpserver
Writing lock file
Generating autoload files

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:

$ sed -i '1i export PATH="$HOME/.composer/vendor/bin:$PATH"' \
   $HOME/.bashrc
$ source $HOME/.bashrc

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:

$ cd $HOME
$ drush --version
 Drush Version   :  7.0.0-alpha5

Manual installation

If you prefer to install Drush manually, then follow these steps:

  1. Start by opening a web browser, and download and uncompress the contents of Drush 7.0.0-alpha5 (https://github.com/drush-ops/drush/releases/tag/7.0.0-alpha5) into your home directory.

  2. Open a terminal and move the drush directory into your system's shared directory:

    $ sudo mv $HOME/drush /usr/share
    
  3. Set proper permissions to the drush executable file:

    $ sudo chmod u+x /usr/share/drush/drush
    
  4. Create a symbolic link of the Drush executable to any of the directories listed at your $PATH environment variable so that you do not have to type /usr/share/drush/drush every time you use it.

    $ echo $PATH
    /home/juampy/.composer/vendor/bin:/usr/local/sbin:
      /usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
      /usr/local/games
    $ sudo ln -s /usr/share/drush/drush /usr/local/bin/drush
    
  5. The next step consists of installing Composer dependencies for Drush:

    $ cd /usr/share/drush
    $ composer install
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
     - Installing d11wtq/boris (v1.0.8)
     - Installing pear/console_table (1.1.5)
     - Installing phpunit/php-token-stream (1.2.2)
     - Installing symfony/yaml (v2.2.1)
     - Installing sebastian/version (1.0.3)
     - Installing sebastian/exporter (1.0.1)
     - Installing sebastian/environment (1.0.0)
     - Installing sebastian/diff (1.1.0)
     - Installing sebastian/comparator (1.0.0)
     - Installing phpunit/php-text-template (1.2.0)
     - Installing phpunit/phpunit-mock-objects (2.1.5)
     - Installing phpunit/php-timer (1.0.5)
     - Installing phpunit/php-file-iterator (1.3.4)
     - Installing phpunit/php-code-coverage (2.0.9)
     - Installing phpunit/phpunit (4.1.3)
     - Installing symfony/process (v2.4.5)
     pear/console_table suggests installing pear/Console_Color (>=0.0.4)
     phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
    Generating autoload files
    
  6. Finally, verify the installation:

    $ cd $HOME
    $ which drush
     /usr/local/bin/drush
    $ drush --version
     Drush Version   :  7.0.0-alpha5
    

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.