How to use Drush Locally with MAMP

The majority of us here at Raincity Studios run MAMP when working locally on projects or for a testing environment. Being introduced to the awesomeness that is Drush yesternight, I went to giver' a try on my local machine.
What is Drush you say?
Drush allows you to easily manage, update, and maintain your modules via command line without having the need to keep a CVS cheat sheet laying around.
In this walkthrough, we'll go through the process of getting Drush working on your local machine, assuming you are running MAMP.
Getting Started
You'll need both a working MAMP installation as well as the Drush project from drupal.org.
The Problem
Following the instruction provided to me from the Drush tarball, I encountered a problem when trying to execute the drush.php file. Upon execution, it returned the full html structure as if I were trying to view it through a browser. This is because you will need to have PHP compiled with CLI-mode (command line interface) enabled. This allows PHP files to be executed via command line, and this CLI mode is only one of the SAPI (System API) types available. For more information on SAPI types, visit PHP.net.
Using MAMP's supplied PHP
Taking a look at the drush.php file located in the sites/all/modules/drush/ folder, I could see that the file was calling upon the php bash command which happens to be pointing at the system's PHP compilation rather than MAMP's.
Firstly, change the php bash command to link to MAMP's PHP:
$ sudo ln -f /Applications/MAMP/bin/php5/bin/php /usr/bin/php
The -f flag unlinks the current target file, if it exists, and links it again with the provided path.
Second, create a link to drush.php in a directory that is in your $PATH, e.g. (this is a step that is inside the README.txt that comes along with the drush tarball):
$ ln /path/to/drush.php /usr/bin/drush
In my case it was:
$ ln /Applications/MAMP/htdocs/d5.7/sites/all/modules/drush/drush.php /usr/bin/drush
Lastly, initialize drush by moseying over to your Drupal root directory, in my case this was:
$ cd /Applications/MAMP/htdocs/d5.7
/Applications/MAMP/htdocs/d5.7 $ drush
Usage: drush.php [options] ...
Options:
-r , --root= Drupal root directory to use (default: current directory)
-l , --uri= URI of the drupal site to use (only needed in multisite environments).....
Additional Features
There are additional features for drush such as the ability to install and update your modules from the command line using CVS, wget, or curl. Additional modules are dependent or suggested in addition to enabling these features. The Update Status module, which checks with drupal.org once a day to see if there are new officially released versions of Drupal and any modules that you are running, and the CVS Deploy, which helps sites that are deployed directly from a CVS workspace. Out of the box, Update status does not know the status of any module that was not installed via a tarball produced by drupal.org, which is why we use CVS deploy.
One final example is the provisioning module, which is a set of extensions to drush that deal with entire sites and install profiles. The provisioning module is the back end interface for our hostmaster mass hosting install profile. A simple example is provided directly on the provisioning project page, showing how you can install an entire new site, based on an install profile:
drush.php provision install somesite.com
The provisioning framework, like drush, is also extensible, so backups, upgrades, and rollbacks will also eventually be handled using this same method. You can also just use the provisioning framework along with drush to help automate your workflow, and not use the rest of the hostmaster framework.













Thanks for the tip!
I was having this same problem and filed an issue, before catching this.
http://drupal.org/node/222611
No problem!
no problem, glad to have helped :)
So you can call Drush to deploy a whole site
A drush module on one site can be used to roll out a whole different site? Can you also have your drush command linked to site X's installation of the drush file and use Drush to install modules on sites Y and Z?
Hostmaster
The provisioning portion is the part that ties into drush is what enables this. So, the full Hostmaster install (which is itself a Drupal site), can run and manage installs of multiple Drupal installs. Check the Hostmaster documentation for more info.
a little diffferent in MAMP 1.7.1
I ran into a little trouble when trying to change the php bash command to link to MAMP's PHP. I kept getting the following message:
ln: /Applications/MAMP/bin/php5/bin/php: No such file or directory
turns out that in my MAMP 1.7.1 the path is:
ln: /Applications/MAMP/bin/php5/bin/php-config
after that everything else in your guide seemed to work fine.