I was struggling to find a robust solution to install and run Drupal’s Drush in Windows with MySQL and rsync all playing along nicely.
I run virtual machines to get around this for the larger, more sophisticated sites, but it’s nice to be able to fire up Uniform Server (my preferred wamp stack) now and again and just run things locally. I have tried a lot of solutions, but the cleanest so far has been to make use of Babun, a rather cool package developed by Tom Bujok and Lukasz Pielak.

Babun (pronounced Baboon) is a pre-configured Cygwin with a lot of addons and lot’s of other bells and whistles including a zsh/bash shell and Git. You can download and install the software via:
Installation
- Download and install babun
- Run shell from link or right-click
- Install PHP
pact find php# this lists all the php packagespact install phppact find php-#shows you what extensions are availablepact install php-ctype php-curl php-exif php-fileinfo php-gd php-iconv php-intl php-json php-ldap php-mbstring php-mcrypt php-mysql php-pdo_mysql php-simplexml php-pdo_sqlite php-phar php-session php-sockets php-tokenizer php-xmlreader php-xmlrpc php-xmlwriter php-zip php-zlib# this is currently what I have installed- Do not install php-gv as this conflicts with drush
- Edit the php.ini file in .babun/cygwin/etc/php5/ and find and replace
;date.timezone =
with an appropriate time zone e.g.
date.timezone = Europe/London
- Install MySQL client
pact install mysql- Create my.cnf in the .babun/cygwin/etc/ folder and add this:
[client]
host=127.0.0.1
protocol=tcp
[mysqldump]
host=127.0.0.1
protocol=tcp
- Other requirements:
pact install bsdtar
Update and rebase babun
At this point it’s probably worth running an update and a rebase to make sure everything runs as expected. In the shell run:
babun update
Once that has completed (if anything required updating at all) close the shell(s) you have open and launch the rebase.bat file and let it do it’s thing before restarting the babun zsh shell.
Install Composer & Drush
Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Drush
composer global require 'drush/drush'
You might notice the single quotes I have put around the package name. This isn’t shown on the drush documentation but is required to prevent an issue with the zsh shell (the babun bash shell will run this without the quotes.) An alternative when using the zsh shell is to use this command:
noglob composer global require drush/drush
Or place this in the .zshrc file:
alias composer="noglob composer"
Update your .bashrc and .zshrc files
Open your .zshrc file in your cygwin home folder (.babun/cygwin/home/*yourusername*/.zshrc) in the shell (vim), or browse in windows and use notepad++ (remember to make sure you force notepad++ to use unix EOLs) and add this to the beginning or end:
export PATH="$HOME/.composer/vendor/bin:$PATH"
Repeat this for the .bashrc file.
Important: Update your Drupal settings
In your Drupal site’s settings.php add this to the bottom:
if (file_exists(__DIR__ . '/settings.local.php')) {
include __DIR__ . '/settings.local.php';
}
Create a new file in the same folder and name it settings.local.php and copy the database connection details for settings.php into this new file. Finally modify the settings.local.php database host from localhost to 127.0.0.1 e.g.
<?php
// settings.local.php
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'mydatabase',
'username' => 'unhere',
'password' => 'pwhere',
'host' => '127.0.0.1',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
You may have to modify this technique if using Drupal 8.
Phew!
Well done if you got this far 🙂 You should now have an environment to run Drush and all its commands including the powerful sql-sync and rsync commands.
Notes for using your new Babun / Cygwin Windows installation:
- make sure you run babun update after installing all the new software
- if you get error warning run the rebase.bat in the babun folder and everything should be fine.
- take notice of the point on the babun site FAQ about Git – I had to run the suggested config:
git config --global core.autocrlf true - use the shell
whichcommand (which php, which drush) to make sure you are running the expected one and not an old windows installation
Hey, great article. Literally a year of struggling on a windows machine with cygwin, and now it works.
Yay for babun.
ps. installed php-tokenizer for drush 8 support
Thanks Lowell. Good pointer for Drush 8 support, cheers. I have added php-tokenizer in the instructions.
I should also say that I updated the underlying cygwin to 2.2.1 shortly after I wrote this article. It’s not officially supported as a technique in the babun documentation, as far as I can tell, but I ran update.bat in the babun root folder from the windows command line to do the update. Everything seems to be working fine for the last couple of months – but make a backup of your original babun folder first in case it all goes pear shaped!
Thanks to you and Babun I got drush successfully running on Windows 7 and Drupal 8, yay!
I very much appreciate your detailed instructions that even a newbie like myself can follow along!
Glad I could help Joao
Hi,
Trying to install on Win 7 x64 I had the following error:
{ ~ } » curl -sS https://getcomposer.org/installer | php ~ 127
curl: (23) Failed writing body (0 != 16384)
Any ideas?
Hi
I cannot replicate this issue so I cannot debug this, sorry. But you can try the solutions mentioned at http://stackoverflow.com/questions/36879168/error-installing-composer-curl-23-failed-writing-body-0-16133
If all else fails you don’t need to install composer to use drush of course – just follow their installation instructions at http://docs.drush.org/en/master/install/