Drupal kattintgatás nélkül

Avagy egy drupal programozó hétköznapjai

Using Xdebug With MAMP and Acquia Drupal Stack

Recently I have switched from Linux to OS X. In order to continue my job effectively I had to set up a proper development environment. For programming tasks I prefer the NetBeans IDE, which is available for OS X. I have not yet decided about the server side, so currently I’m testing two alternatives. Those are MAMP and the Acquia Drupal Stack which is a great help for Drupal development. I picked Acquia Drupal Stack because most of my tasks are Drupal related and this tool can save me a lot of time. You can watch Gabor Hojtsy’s presentation on Acquia Drupal Stack at DrupalCamp Hungary: here.

Download and install as usual:

As a last step you need to install Xdebug.

Enabling Xdebug in MAMP

Fortunately MAMP contains a pre-compiled xdebug.so file, so you only need to enable it in php.ini. At the same time make sure that Zend optimizer is disabled because it does not work together with Xdebug. Edit php.ini using your favorite text editor:

1
nano /Applications/MAMP/conf/php5/php.ini

Change the end of the file to this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
;[Zend]
;zend_optimizer.optimization_level=15
;zend_extension_manager.optimizer=/Applications/MAMP/bin/php5/zend/lib/Optimizer-3.3.3
;zend_optimizer.version=3.3.3

;zend_extension=/Applications/MAMP/bin/php5/zend/lib/ZendExtensionManager.so

[xdebug]

xdebug.default_enable=1

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

zend_extension="/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"

Restart MAMP and check phpinfo()’s output. If you see the following lines then you’ve successfully enabled Xdebug. MAMP phpinfo xdebug

Enabling Xdebug in Acquia Drupal Stack

Acquia Drupal Stack doesn’t contain a pre-compiled xdebug.so file, so you have two choices. Either you compile it from source or use MAMP’s pre-compiled xdebug.so file. I chose the latter one. (Note: MAMP ships with php 5.2.11, whilst Acquia Drupal Stack uses version 5.2.9.)

Copy xdebug.so from MAMP to Acquia Drupal Stack:

1
2
cd /Applications/acquia-drupal/php/ext/
cp /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so .

Open php.ini using your favorite text editor:

1
nano /Applications/acquia-drupal/php/bin/php.ini

Add the following lines to the end:

1
2
3
4
5
6
7
8
9
10
11
[xdebug]

xdebug.default_enable=1

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9080
xdebug.remote_autostart=1

zend_extension=/Applications/acquia-drupal/php/ext/xdebug.so

In this example Xdebug is using port 9080, which is needed to make sure that MAMP and Acquia Drupal Stack don’t use the same port. If you are not going to use them simultaneously then port 9000 is also fine here.

You can use phpinfo() from Acquia Drupal Stack’s settings: Acquia Settings

If you see the following then you’ve successfully enabled Xdebug: Acquia phpinfo xdebug

Real time debugging with NetBeans

Below you can see the settings for PHP debugging in MAMP environment: NetBeans xdebug

If you use Acquia Drupal Stack, change PHP 5 Interpreter and Debugger Port settings respectively.

1
2
PHP 5 Interpreter: /Applications/acquia-drupal/php/bin/php
Debugger Port: 9080

Web browser settings should look like this way:

NetBeans Browser Options

NetBeans Settings Web Browsers

Now you only need to set a break point and start debugging.

I would like to thank itarato and zserno for their help in writing this article. This article was translated to English by zserno. For the original hungarian article click here.

References: