Sag Rising

Notes to Myself

An Amateur Programmer's PHP IDE

Posted by Richard Cockrum on April 28, 2008

One of the things I've missed most in learning PHP is a debugger. A debugger is a necessity for productive work in any programming language. You need a debugger to step through code to understand how it works and is being called. You need a debugger to examine variables.

But I'm basically a hobbyist, and at this point don't want to spend the money for a professional ide like Zend Studio or PHPEdit which come with built-in debuggers. PDT, Eclipse specialized for PHP programming, is a free option, but it is also a large piece of software that is overkill for my needs, especially since I work off a memory stick quite frequently and don't need another application that will take several hundred megabytes of space.

Fortunately, I've finally found a portable IDE that fits my needs, Notepad++ and XDebug.

I've been using Notepad++ as my PHP editor. It has just about everything I want - syntax highlighting, a good search function, basic brace checking, the ability to show white space marks, conversion between Unix style and Windows style line feeds, the ability to use different character encodings, macros, function folding, and the ability to specialize to a specific language. Still and all, it is an editor. As I worked I would wistfully remember my C++ IDE.

But, Notepad++ has a plugin interface. It can be extended to do all sorts of things. So I started wondering if there was a debugging extension for it.

After much scouring of the internet I found there is one, DBPg, a client interface for XDebug. XDebug is the opensource PHP debugger that, along with the Zend debugger, is one of the most popular debuggers for PHP. XDebug lets you set breakpoints and step through your code, set up watches on the variables you want to view, perform stack traces, and view PHP's handler vars like $_POST, $_GET, $_COOKIE, $_SESSION. When I found it, and then when I found the plugin for Notepad++ that acts as an interface for it, I knew my debugging problems were over.

Setting up Notepad++ to work with XDebug is fairly easy.

First, install XDebug on your server. I placed it in my php extensions directory. Then I added the following lines to my php.ini file to get XDebug working:

[debug]
zend_extension_ts="/wos/php5/ext/php_xdebug-2.0.2.dll"
xdebug.remote_enable=1 
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.idekey=default

Note 1: I use zend_extension_ts because I'm running a multithreaded version of PHP. If I were runnng a single threaded version of PHP, I would use zend_extension (without the _ts).

Note 2: /wos/php5/ext/php_xdebug-2.0.2.dll is the path to where XDebug is on my filesystem.

Restart your server if need be to activate the debugger.

Second, prepare Notepad++ for debugging. Place the DBGp plugin in Notepad++'s plugin directory, then open Notepad++. DBGp will be a new item in the Plugins menu. I configured DBGp by telling it refresh both the local and global contexts on every step, then mapped my local files to the server files. Since I'm running a local server for development, I ignored the remote server ip and the IDE KEY, then set both the remote path and the local path the same, in my case f:\wos\www, since that is where I have Habari, the script I'm currently working with, located.

That's it. Notepad++ is set up. Notepad++ has several other plugins that make life easier. Visit it's homepage to browse through them.

To start debugging, open the file you want to work on in Notepad++, then click on Debugger in the DBGp menu. The debugger will open at the bottom of your Notepad++ window. Open up your browser and navigate to the page you want to debug. In the address bar type ?XDEBUG_SESSION_START=test at the end of the url, then refresh the page. The Notepad++ icon will flash to let you know it is connected, and you can get to work.

If you're using Firefox as your browser, there is an extension you can get to make the task even easier - XDebug Helper. After it is installed, instead of typing the start message, simple click on the icon at the bottom of your browser window and your debug session will start.

The only issue I've had with this setup is that when XDebug is running and a page first loads, Apache will throw an exception. Windows (I'm running XP Service Pack 2) will ask if I want to submit an error report to Microsoft. On checking what is in the error report I see that the problem is with XDebug. I tell it not to send an error report, then get on with my work. Everything seems to work fine. I can debug PHP rather than wondering where my code is wrong. Productivity is up. My understanding improves. I can work purposefully rather than randomly.

Life is good.

This entry is filed under , and . You can follow any responses to this entry through the feed . New comments are currently closed.

6 Responses to An Amateur Programmer's PHP IDE

Thank you for your tutorial which is very helpful. I agree with your sentiments on the popular IDE which is costly if not free but bloated and simply want to have an editor that is lightweight. To have an integrated debugger like XDebug in Notepad++ is a real blessing. Initially I couldn't figure out how to integrate and use the debugger, but after going through your tutorial, it all became clear to me.

I follow all your instructions, the only difference is I use d:\www as output folder.

I have some printscreens here:

If you're please kind to give me a useful advice.

http://stackoverflow.com/questions/7791010/unable-to-configure-notepad-dbgp-plugin-xdebug-already-installed

Thanks

I wish I could share your experience. I simply cannot get it to work.

Here is my php.ini (I use WAMP).

Any ideas anyone?

zend_extension = "c:/wamp/bin/php/php5.3.8/ext/php_xdebug-2.2.0RC1-5.3-vc9.dll"

[xdebug]
xdebug.remote_enable = off
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "c:/wamp/tmp"

zend_extension_ts="c:/wamp/bin/php/php5.3.8/ext/php_xdebug-2.2.0RC1-5.3-vc9.dll"
xdebug.profiler_output_dir = "c:/wamp/tmp/xdebug"
xdebug.profiler_output_name = "cachegrind.out.%p"
xdebug.profiler_enable = 1
xdebug.profiler_append=0
xdebug.extended_info=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=xdebug
xdebug.remote_log="c:/wamp/tmp/xdebug/xdebug.log"
xdebug.show_exception_trace=0
xdebug.show_local_vars=9
xdebug.show_mem_delta=0
xdebug.trace_format=0

John

What do you think?
Comments for this post are disabled.