Install Drush in Windows using composer

Drush give us text commands to accomplish task that significantly save us amount of time rather than using the web interface clicking around with a mouse. We will look at installing latest version of Drush on Windows using composer. The following instructions are done in all in one server XAMPP environment.

  1. First we will install Minimalist GNU for Windows which can be found here http://www.mingw.org/wiki/msys. This is a minimalist Unix box on Windows which is equipt with basic Unix commands.
  2. After installing Msys, make sure that the command line is using the PHP bundled with XAMPP rather than the PHP in your OS. To do this, open Msys and execute the following command to download :
    
    which php
    
    
  3. Add the path of your XAMPP's PHP directory to system PATH. Click the "Start" Menu button then right click the "Computer" on the right side of the menu and select "Properties". A window will pop-up, click "Advanced system settings" in the left area. The "System properties" window will appear. Click the "Environment Variables..." button. Add "C:\xampp\php;C:\xampp\mysql\bin" to the "PATH" variable.

  4. Close the Msys window and open it again to make sure it picked up the changes made in system PATH.
  5. Download the composer script by executing:
    
    curl -sS https://getcomposer.org/installer > installer.php
    php installer.php
    rm installer.php
    
    
  6. Now we will install Drush, execute:
    
    ./composer.phar global require drush/drush:dev-master
    
    

    It will install several software dependencies and Drush. We will see output something like this:

    
    Changed current directory to C:/Users/Webfoobar/AppData/Roaming/Composer
    ./composer.json has been created
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
      - Installing symfony/polyfill-mbstring (v1.1.0)
        Downloading: 100%
    
      - Installing symfony/var-dumper (v3.0.3)
        Downloading: 100%
    
      - Installing symfony/yaml (v3.0.3)
        Downloading: 100%
    
      - Installing pear/console_table (v1.3.0)
        Downloading: 100%
    
      - Installing psr/log (1.0.0)
        Downloading: 100%
    
      - Installing jakub-onderka/php-console-color (0.1)
        Downloading: 100%
    
      - Installing jakub-onderka/php-console-highlighter (v0.3.2)
        Downloading: 100%
    
      - Installing dnoegel/php-xdg-base-dir (0.1)
        Downloading: 100%
    
      - Installing nikic/php-parser (v2.0.1)
        Downloading: 100%
    
      - Installing symfony/console (v3.0.3)
        Downloading: 100%
    
      - Installing psy/psysh (v0.7.1)
        Downloading: 100%
    
      - Installing drush/drush (dev-master cab2239)
        Cloning cab2239efb4c9f320232edc027c9a2eb6864530a
    
        Skipped installation of bin drush.bat for package drush/drush: name conflicts with an existing file
    symfony/var-dumper suggests installing ext-symfony_debug ()
    pear/console_table suggests installing pear/Console_Color2 (>=0.1.2)
    symfony/console suggests installing symfony/event-dispatcher ()
    symfony/console suggests installing symfony/process ()
    psy/psysh suggests installing ext-pcntl (Enabling the PCNTL extension makes PsySH a lot happier :))
    psy/psysh suggests installing ext-posix (If you have PCNTL, you'll want the POSIX extension as well.)
    psy/psysh suggests installing ext-readline (Enables support for arrow-key history navigation, and showing and manipulating command history.)
    psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
    drush/drush suggests installing drush/config-extra (Provides configuration workflow commands, such as config-merge.)
    drush/drush suggests installing ext-pcntl (*)
    Writing lock file
    Generating autoload files
    
    
  7. To make drush can be executed globally, add the "%USERPROFILE%\AppData\Roaming\Composer\vendor\bin" to system PATH.
  8. Let's make the composer script "composer.phar" executable globally as well. Move the script to "~/AppData/Roaming/Composer/vendor/bin"
    
    mv composer.phar ~/AppData/Roaming/Composer/vendor/bin
    
    
  9. To refresh with the updated system PATH environment, close and open the Msys window.
  10. To update Drush as well as softwares installed using Composer, execute:

        
    composer global update  
        
      
  11. Good thing about composer, it enables us to switch the installation of Drush version easily. Lets take a look first what available versions of Drush that we can install by executing:

    
    composer global show drush/drush
    
    

    ... and it will show something like this:

    
    name : drush/drush
    descrip. : Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.
    keywords :
    versions : dev-master, 8.0.x-dev, 8.0.0-beta11, 7.x-dev, 7.0.0, 7.0.0-rc2, 7.0.0-rc1, 7.0.0-alpha9, 7.0.0-alpha8, 7.0.0-alpha7, 7.0.0-alpha6, 7.0.0-alpha5, 7.0.0-alpha4, 7.0.0-alpha3, 7.0.0-alpha2, 7.0.0-alpha1, 6.x-dev, 6.6.0, 6.5.0, 6.4.0, 6.3.0, 6.2.0, 6.1.0, 6.1.0-rc1, 6.0.0, 6.0.0-rc4, 6.0.0-rc3, 6.0.0-rc2, 6.0.0-rc1, dev-process, dev-process-replacement, dev-prevent-segfault-on-large-yaml-files, dev-6.x-fulltest, dev-bootclasses, dev-better_bootstrap, dev-bash-example-fix, dev-dev/1268, dev-dev/1234, dev-dev/1159, dev-si-profile, dev-drupalorg-projects, dev-manage-path, dev-revert-1115-fix-unary-operator-expected, dev-disable-8, dev-migrateTest, dev-site-local, dev-sa-labels, dev-userabort-exitcode, dev-theme-commandfiles, dev-script-status, dev-master-fulltest, dev-library-caching,dev-exclude-vendor, dev-drush-console, dev-make-fixes, dev-queue-refactor, dev-config-get-overridden, dev-config-outside-root, dev-request-uri-change, dev-yaml-info-file, dev-sql-sync-command-definition
    type : library
    license : GNU General Public License v2.0 or later (GPL-2.0+) (OSI approved) http://spdx.org/licenses/GPL-2.0+#licenseText
    source : [git] https://github.com/drush-ops/drush.git f9bf23f509499da4b364c748564670eeeb21460b
    dist : [zip] https://api.github.com/repos/drush-ops/drush/zipball/f9bf23f509499da4b364c748564670eeeb21460b f9bf23f509499da4b364c748564670eeeb21460b
    names : drush/drush
    autoload
    psr-0
    Drush => lib/
    requires
    symfony/yaml ~2.2
    pear/console_table ~1.2.0
    d11wtq/boris ~1.0
    symfony/var-dumper ^2.6.3
    php >=5.4.5
    requires (dev)
    phpunit/phpunit >=3.5
    symfony/process 2.4.5
    suggests
    drush/config-extra Provides configuration workflow commands, such as config-merge.
    
    

    Under "versions" shows all Drush versions available.

  12. Now, let's try to switch the Drush version to stable version 7. Execute this lines:
    
    composer global require drush/drush:7.*
    composer global update
    
    
  13. Verify the Drush version by:
    
    drush --version
    
    
  14. (Optional) Install "Registry Rebuild":
    
    drush @none dl registry_rebuild
    
    

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.