A Drupal Development Environment on OS X with MAMP Pro, Eclipse, xDebug, and Drush

MAMP

These instructions are somewhat specific to MAMP PRO 2.1.1

Download, install, and launch MAMP Pro. Under the PHP tab, select php 5.3.x from version pulldown. Click "Apply". Click "Start".

Add the MAMP executables to your path.

chmod +x /Applications/MAMP/bin/php/php5.3.14/bin/*
echo "export PATH=/Applications/MAMP/bin/php/php5.3.14/bin:/Applications/MAMP/Library/bin:\$PATH" >> ~/.profile
. ~/.profile

Add a symlink to the MAMP Mysql socket to allow drush to connect.

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

xDebug

In MAMP menu, go to File->Edit Template->PHP 5.3.x php.ini, and uncomment the xdebug zend_extension line, and add:

xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xebug.remote_handler=dbgp

Restart the stack ("Stop", then "Start") and click "WebStart" to verify xDebug is enabled (phpinfo, search for "xdebug").

Eclipse

Download and install Eclipse+PDT or Zend Studio.

Configure eclipse by following the instructions under "Eclipse Hook Templates" and "PHP Development Tools (PDT)" on the Drupal Configuring Eclipse page.

In Eclipse preferences, open PHP->PHP Executables, and set the php interpreter to be the MAMP 5.3.x executable.

Eclipse PHP Interpreter

Eclipse PHP Interpreter

Create a test project to see if xDebug is working:

  1. File->New->Project: "PHP Project from Existing Directory". Set the location to the MAMP htdocs directory /Applications/MAMP/htdocs

    New Project

    New Project

  2. Open index.php, set breakpoint at first line of php (double click to left of line numbers).

    A Breakpoint

    A Breakpoint

  3. Open firefox, install easy Xdebug extension.

  4. Go to http://localhost:8888/.

  5. Enable debugging by clicking the green bug icon in the status bar.

    Easy Xdebug Enabled

    Easy Xdebug Enabled

  6. Reload, and eclipse should pause execution at your breakpoint.

    Debugging

    Debugging

Drush

pear channel-discover pear.drush.org
pear install drush/drush
drush

Install Drupal

cd /Applications/MAMP/htdocs
drush dl drupal

In MAMP, give MySQL a password, launch phpMyAdmin, and create a database for Drupal. Edit /Applications/MAMP/htdocs/sites/brianfisher.name/settings.php to configure Drupal to connect to the database.

Go to http://localhost:8888/

Performace

MYSQL

You may get "MySql server has gone away" errors. To fix, in MAMP, edit the mysql configuration by going to file->edit template->mysql. Change max_allowed_packet to

max_allowed_packet =  16M

PHP

Increase both the MAMP PHP memory limit. In MAMP, edit the php configuration

file->edit template->php->php5.3

change memory_limit to

memory_limit =  256M

Increase the CLI PHP memory limit. To figure out where your CLI php.ini file is, use

which php

php -i | grep  php.ini

change memory_limit to

memory_limit =  -1

References

Tags: