Debug php in emacs with geben

While PHP-developing it sometimes is just too tedious to do those ‘add a echo here and there, then reload and search the echoed strings on the screen'-loops. So I searched for a debugger for my favourite editor emacs. After a lengthy install procedure I finally got it running: With geben on emacs you can debug PHP (step through and evaluate expressions)

geben.png geben in action Installation Install xdebug php5-module get xdebug for php (See “xdebug für ubuntu (german)”)

01 sudo pecl install xdebug

→ File lies at /usr/lib/php5/20060613+lfs/ edit php.ini (see “easy php debugging using debug and vim”)

Put these under “Module Settings”:

    01 zend_extension=/usr/lib/php5/20060613+lfs/
02 [debug]
03 ; Remote settings. Adapt if you?re not running apache on localhost
04 xdebug.remote_autostart=off
05 xdebug.remote_enable=on
06 xdebug.remote_handler=dbgp
07 xdebug.remote_mode=req
08 xdebug.remote_host=localhost
09 xdebug.remote_port=9000

Restart apache:

01 /etc/init.d/apache2 restart

Install required packages

Unfortunately, geben doesn't work with the ubuntu “gutsy gibbon” packages. So do not do apt-get eieio. Instead: download cedet and eieio from and copy both into ~/elisp/

    01 cd ~/elisp/
02 tar -xzvf *.tar.gz
03 cd cedet*
04 make
05 cd ../eieio*
06 make

add this to .emacs:

    01 (add-to-list 'load-path "~/elisp/eieio-0.17")
02 (load-file "~/elisp/cedet-1.0pre4/common/cedet.el")

get debugclient from (currently: this file)

rename it to debugclient and move to usr/local/bin install geben

download geben from

unpack it into ~/elisp/

add this to your .emacs-file:

    01 (add-to-list 'load-path "/home/phred/elisp/geben")
02 (add-to-list 'load-path "/home/phred/elisp/geben/gud")


Restart emacs. Type alt-x geben. Load the script you want to debug in firefox with ?XDEBUG\_SESSION\_START=1 appended

Voilà, that's it. After pressing space to ‘activate' geben you can use this keys:

    01 spc step into/step over
02 i   step into
03 o   step over
04 r   step out
05 b   set a breakpoint at a line
06 u   unset a breakpoint at a line
07 g   run
08 e   eval expression (to inspect variables: best is probably print_r($this, true))
09 q   stop debugger

Update: After some usage it bugged me to always type print\_r($var, true) to inspect a variable. And then, the print\_r-output is cut after 1024 chars. Knowing absolutely nothing about lisp I did some very lame changes to the geben code.

With these changes I'm able to type ‘E' and then write $variable and geben writes all the output to the message-buffer. Download the diff and patch the geben-sourcecode with

patch -i geben.diff